Method missing in Ruby
Labels:
Ruby
When you call a ruby method which doesn't exist, i.e if ruby object fails to find any such method, NoMethodError is raised. It can be avoided using a method avilable in ruby called Method MissingTo handle NoMethodError gracefully, Method missing can be used in ruby.Consider the example below
Class Sap
def first
puts "You are in first method"
end
def method_missing(method)
puts "There is no method called #{method} in class Sap"
end
end
ob = Sap.new
ob.frst
The output will be
"There is no method called frst in class Sap"
Post a Comment