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
Please login to continue.