Skip to content

Instantly share code, notes, and snippets.

@EdwinRozario
Created February 23, 2012 05:36
Show Gist options
  • Save EdwinRozario/1890696 to your computer and use it in GitHub Desktop.
Save EdwinRozario/1890696 to your computer and use it in GitHub Desktop.
Method Missing
class Foo
MYMETHODS = ['van', 'car', 'bus']
def foo(x)
case x
when 'van' then return 'Long vehicle'
when 'car' then return 'Small vehicle'
when 'bus' then return 'Very Long vehicle'
else return 'None'
end
end
MYMETHODS.each do |method|
define_method method do
foo(method)
end
end
def method_missing(param)
return "Method #{param} is not defined"
end
end
o = Foo.new
puts o.van
puts o.car
puts o.bus
puts o.truck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment