Testing Whether an Object Is String-like : respond_to « Reflection « Ruby






Testing Whether an Object Is String-like


'A string'.respond_to? :to_str              # => true
Exception.new.respond_to? :to_str           # => true
4.respond_to? :to_str                       # => false

 








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.The method respond_to? tests to see whether an instance of Address has access to :given_name, inherited from the Name class.
3.Check respond_to? for new added instance method
4.Check respond_to? for new added singleton method