Ruby - Advanced Metaprogramming
What will be the output of this Ruby code?
class Dog
def initialize(name)
@name = name
end
end
fido = Dog.new('Fido')
fido.instance_eval { def speak; "Woof! I'm #{@name}"; end }
puts fido.speak
rex = Dog.new('Rex')
puts rex.respond_to?(:speak)