Ruby - Advanced Metaprogramming
What will be the output of the following Ruby code?
module M
module_eval do
def hello
'Hello from M'
end
end
end
class C
include M
end
puts C.new.helloWhat will be the output of the following Ruby code?
module M
module_eval do
def hello
'Hello from M'
end
end
end
class C
include M
end
puts C.new.hellohello is defined inside module M using module_eval, so it becomes an instance method of M.C includes M, so instances of C have hello method. Calling C.new.hello returns 'Hello from M'.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions