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