4 ms·
Well, a trivial example: class Foo def bar puts "Hello from Foo" end end a = Foo.new def a.bar puts "Hello from
by jballanc 14y ago
Well, a trivial example:
class Foo
def bar
puts "Hello from Foo"
end
end
a = Foo.new
def a.bar
puts "Hello from a special Foo"
end
Now, even if you change the definition of "bar" in Foo's class definition, "a" will still have it's own version. This might not seem like a big deal, but as you do more metaprogramming with Ruby, more examples like this pop up.