Ruby - Metaprogramming Fundamentals
What will be the output of this Ruby code?
class CatchAll
def method_missing(name, *args)
"Called #{name} with #{args.join(', ')}"
end
end
obj = CatchAll.new
puts obj.hello('world')What will be the output of this Ruby code?
class CatchAll
def method_missing(name, *args)
"Called #{name} with #{args.join(', ')}"
end
end
obj = CatchAll.new
puts obj.hello('world')hello which is undefined and returns a string with method name and arguments.obj.hello('world') triggers method_missing with name :hello and args ['world'], so output is "Called hello with world".15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions