/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Ex: # > foo = OpenStruct.new # > foo.add :bar # > foo.bar.a = 10 # > foo.bar.a # => 10 # > foo.add 'bar.baz.bax' # > foo.bar.baz.bax.something = 100 # > foo.bar.baz.bax.something # => 100 require 'ostruct' class OpenStruct def add name last = self name.to_s.split('.').each do |n| o = OpenStruct.new last.send n.concat('=').intern, o last = o end return last end end