Module: Nestable
Instance Method Summary collapse
Instance Method Details
#nests(mapping) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mixins/nestable.rb', line 3 def nests(mapping) # Setup an accessor for all nested instances. attr_accessor *mapping.keys # Create a nested instance automatically on initialize. define_method(:initialize) do |arguments = nil| mapping.each do |attribute, klass| self.instance_variable_set "@#{attribute}".to_sym, klass.new end super arguments if arguments end end |