Mega Code Archive

 
Categories / Ruby / Reflection
 

Responding to Calls to Undefined Methods

class MyClass   def defined_method     'This method is defined.'   end   def method_missing(m, *args)     "Sorry, I don't know about any #{m} method."   end end o = MyClass.new o.defined_method                         # => "This method is defined." o.undefined_method # => "Sorry, I don't know about any undefined_method method."