3 ms·
It's adding structure (methods to classes) at runtime which normally would require writing source code. That is treating the program as data; it manipulates the
by scott_s 17y ago
It's adding structure (methods to classes) at runtime which normally would require writing source code. That is treating the program as data; it manipulates the object system as any other kind of data.
You seem confident that your definition of metaprogramming is the accepted definition, but I don't see evidence of that.
- aaronblohowiak 17y ago"It's adding structure (methods to classes) at runtime which normally would require writing source code." -- the linked blog post doesn't do this, though it is possible.
- scott_s 17y agoThen what is this? 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.
- aaronblohowiak 17y agoRuby, not javascript.