Alle mercoledÃ¬ 30 maggio 2007, Maurice G. ha scritto:
object has a :foo method defined.
Maurice B. Gladwell
Are you sure find_by_name is a class method and not an instance method
do you call SomeRailsModel.find_by_name or something like
SomeRailsModel.new.find_by_name)? I don’t know Rails, so I may be wrong,
to me it seems that find_by_name is an instance method. If it is so,
can’t expect SomeRailsModel.respond_to? to return true. This has nothing
do with the method being dynamically generated. For instance,
gives false, because select is an instance method.
gives true, instead.
If you want to know whether a class has an instance method without
creating an instance of the class, you can call instance_methods on the
class. It will return an array with the names of the methods instances
class will have. For example:
=>[“select”, “=”, “inspect”, “<<”, … ]
In your case, if find_by_name is an instance method, you can do this:
I hope this helps