Ruby - Advanced Metaprogramming
What will be the output of this Ruby code?
module M module_eval 'def shout; "Hey!"; end' end class C include M end puts C.new.shout
What will be the output of this Ruby code?
module M module_eval 'def shout; "Hey!"; end' end class C include M end puts C.new.shout
The method shout is defined inside module M using a string passed to module_eval.
Class C includes M, so C.new.shout calls the method and prints "Hey!".
15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions