Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plukevdh/262ce284ff4bb6466573 to your computer and use it in GitHub Desktop.
Save plukevdh/262ce284ff4bb6466573 to your computer and use it in GitHub Desktop.
method missing for finders
# This...
def by_id(id)
filter_by(:id, id)
end
def by_email(email)
filter_by(:email, email)
end
# vs...
def method_missing(method, *args)
match = /by_(?<filter>\w+)/.match(method)
if match
filter_by match[:filter], args
else
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment