Ruby access magic
问题 Assume, I have the following class: class MyClass attr_accessor :vars def initialize @vars = [] end def add_var var @vars << var end end I want to access inners vars like this: x = MyClass.new('root') x.add_var 'test' x.add_var 'something' x.add_var Myclass.new('google') x.google.add_var 'nice' puts x.test puts x.something puts x.google.nice Generally speaking, is it possible? What/where should I dig for? 回答1: It's part of the standard Ruby library, and it's called OpenStruct: #!/usr/bin