The method respond_to? tests to see whether an instance of Address has access to :given_name, inherited from the Name class. : respond_to « Reflection « Ruby






The method respond_to? tests to see whether an instance of Address has access to :given_name, inherited from the Name class.


#!/usr/bin/env ruby

class Name
  attr_accessor :given_name, :family_name
end

class Address < Name
  attr_accessor :street, :city, :state, :country
end

a = Address.new
puts a.respond_to?(:given_name) # => true

 








Related examples in the same category

1.The respond_to? method from Object checks to see if a given object responds to a given method.
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