Class: YardTypes::DuckType
Overview
A DuckType constraint is specified as #some_message, and indicates that the object must respond to the method some_message.
Instance Attribute Summary collapse
-
#message ⇒ String
readonly
The method the object must respond to; this does not include the leading # character.
Attributes inherited from Type
Instance Method Summary collapse
-
#check(obj) ⇒ Boolean
trueif the object responds tomessage. -
#initialize(name) ⇒ DuckType
constructor
A new instance of DuckType.
Methods inherited from Type
Constructor Details
#initialize(name) ⇒ DuckType
Returns a new instance of DuckType.
90 91 92 93 |
# File 'lib/yard_types/types.rb', line 90 def initialize(name) @name = name @message = name[1..-1] end |
Instance Attribute Details
#message ⇒ String (readonly)
Returns The method the object must respond to; this does not include the leading # character.
87 88 89 |
# File 'lib/yard_types/types.rb', line 87 def @message end |
Instance Method Details
#check(obj) ⇒ Boolean
Returns true if the object responds to message.
97 98 99 |
# File 'lib/yard_types/types.rb', line 97 def check(obj) obj.respond_to? end |