Source: ruby’s respond_to? for checking if a method exists [prateekdayal.net]


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

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/1BMijCTcXqk/10519