Reputation: 197
I'm trying to get the list of methods defined in a Rails model without the attributes and reflections.
The code I have thus far is as follows but it only shows the database columns and has_many, etc definitions. I need the custom methods in the model as well.
class.reflections.keys.each do |key|
define_method key do
@object.send key
end
end
class.attribute_names.each do |sym|
define_method sym do
@object.send sym
end
end
I've tried ".methods", etc but it includes or excludes the methods I've defined.
Upvotes: 1
Views: 554
Reputation: 21
Use MyClass.instance_methods(false)
, but make sure to pass false
as an argument if you don't want it to return the methods defined in the superclasses.
Additionally, use MyClass.singleton_methods(false)
for class methods.
More info:
Upvotes: 2