respond_to?

respond_to?(name, include_private = false)
Instance Public methods

A Person object with a name attribute can ask person.respond_to?(:name), person.respond_to?(:name=), and person.respond_to?(:name?) which will all return true. It also define the attribute methods if they have not been generated.

class Person < ActiveRecord::Base
end

person = Person.new
person.respond_to(:name)    # => true
person.respond_to(:name=)   # => true
person.respond_to(:name?)   # => true
person.respond_to('age')    # => true
person.respond_to('age=')   # => true
person.respond_to('age?')   # => true
person.respond_to(:nothing) # => false
doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.