Skip to content

Instantly share code, notes, and snippets.

@rsinger
Created May 31, 2012 17:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsinger/2844996 to your computer and use it in GitHub Desktop.
Save rsinger/2844996 to your computer and use it in GitHub Desktop.
method_missing example
class Foo
def method_missing(method_name, *args)
# method_name is a symbol
if method_name.to_s =~ /^find_by_/
self.find_by_magic_method(method_name, args)
elsif method_name.to_s =~ /^other_dynamic_method_/
self.do_other_dynamic_method(method_name, args)
end
# If we get here, we'll get a NoMethodError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment