Friday, October 24, 2008

String boolean: MethodMissing fun!

Check out this one, this is way i love rails.

elad = "smart"
elad.smart? # => true


using method_missing on the String object


def method_missing(method_name, *arguments)
if method_name.to_s.ends_with?("?")
self == method_name.to_s[0..-2]
else
super
end
end

No comments:

Post a Comment

Tell me what you think