The respond_to? method from Object checks to see if a given object responds to a given method. : respond_to « Reflection « Ruby






The respond_to? method from Object checks to see if a given object responds to a given method.




class A
  attr_accessor :x
end

a = A.new

a.respond_to? :x # => true
a.respond_to? :x= # => true
a.respond_to? :y # => false

 








Related examples in the same category

1.The method respond_to? tests to see whether an instance of Address has access to :given_name, inherited from the Name class.
2.Testing Whether an Object Is String-like
3.Check respond_to? for new added instance method
4.Check respond_to? for new added singleton method