I have a Ruby object (an ActiveRecord object, specifically) named User
. It responds to methods like find_by_id
, find_by_auth_token
, etc. However, these aren't methods that are defined via def
or define_method
. Instead, they are dynamic methods that are handled via method_missing
.
I'd like to obtain a reference to one of these methods via Object#method
, e.g.:
User.method(:find_by_auth_token)
It doesn't look like this works though. The best solution I've come up with is:
proc { |token| User.find_by_auth_token(token) }
Is there any other way around using such a wrapper method as this? Am I really unable to use Object#method
for dynamic methods?