sword_symbol = "*********"
drew.metaclass.send(:define_method, 'swing') do |sound_effect|
puts "#{name}: #{sword_symbol} #{sound_effect}"
end
drew.swing 'slash!!'
I understand that to add the swing method without writing the source code to do it. This use is trivial, but it's easy for me to extrapolate to how one could make the newly created method depend on runtime information.
Comments
Then what is this?
I understand that to add the swing method without writing the source code to do it. This use is trivial, but it's easy for me to extrapolate to how one could make the newly created method depend on runtime information.Ruby, not javascript.