Contents

Roo

object.responds_to?

Used to determine if an object can respond to a particular getter or method.

object.responds_to?(name as Text) as Boolean

Parameters

  • name: Text. The name of the getter or method that you’d like to know if this object responds to

Returns

  • Boolean object

Example

class Dog {
    bark() {
        print("Woof woof!")
    }
}

var i = 10
print(i.responds_to?("reverse")) # => False
print("Forwards".responds_to?("reverse")) # => True

var d = Dog();
print(d.responds_to?("bark")) # => True
print(d.responds_to?("sleep")) # => False