Slide 120
Slide 120 text
SAMPLE USAGE
DynamicClass
Animal = DynamicClass.new do
def speak
"The #{type} makes a #{sound} sound!"
end
end
dog = Animal.new(type: 'dog', sound: 'woof')
# => #
dog.speak
# => "The dog makes a woof sound!"
dog.ears = 'droopy'
dog[:nose] = ['cold', 'wet']
dog['tail'] = 'waggable'
dog
# => #
Animal.instance_methods(false)
# => [:to_h, :speak, :type=, :type, :sound=, :sound, :ears=, :ears,
:nose=, :nose, :tail=, :tail]