Easy querying of rails methods in console
April 13th, 2007
When debugging or inspecting Rails code, it is often nice to see just those methods that are added by rails or custom ActiveRecord object. This simple addition to ~/.irbrc does just that:
if ENV['RAILS_ENV']
class Object
protected
def rails_meths; (public_methods - Object.public_instance_methods).sort; end
def cust_rails_meths
(rails_meths - ActiveRecord::Base.public_instance_methods).sort;
end
end
end.
Now you can fire up script/console, and do stuff such as
>> item = MyOwnModelClass.find(42)
>> item.public_methods # shows so much stuff
>> item.rails_meths # shows only rails stuff
>> item.cust_rails_meths # even more terse listing
Of course, you were aware of obj.attributes already.

Leave a Reply