DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Check If A Ruby Method Exists

  • submit to reddit
        Source: <a href="">ruby’s respond_to? for checking if a method exists</a> []

Ruby has a function called respond_to? that can be used to seeing if a particular class or object has a method with a certain name. The syntax is something like
User.respond_to?('name') # returns true is method name exists otherwise false