I am currently looking for a software/web development job preferably as a Rails-based developer.
Please email me at email@example.com. Thanks in advance for any leads!
How To Check If A Class Or Instance Has A Method Defined In Ruby
Posted by Weston Ganger
When writing my plugin Spreadsheet Architect I needed to check if methods were defined on both the class and instances. Heres two fast ways to do this:
Post.respond_to?(:item_name) #=> false @post.respond_to?(:item_name) #=> true # Check if the instance method is defined Post.method_defined?(:some_instance_method) #=> false @post.method_defined?(:some_instance_method) #=> true
Related External Links: