Created
February 23, 2012 05:36
-
-
Save EdwinRozario/1890696 to your computer and use it in GitHub Desktop.
Method Missing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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