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. -
#description ⇒ String
An English phrase describing this type.
-
#initialize(name) ⇒ DuckType
constructor
A new instance of DuckType.
Methods inherited from Type
Constructor Details
#initialize(name) ⇒ DuckType
Returns a new instance of DuckType.
108 109 110 111 |
# File 'lib/yard_types/types.rb', line 108 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.
105 106 107 |
# File 'lib/yard_types/types.rb', line 105 def @message end |
Instance Method Details
#check(obj) ⇒ Boolean
Returns true if the object responds to message.
120 121 122 |
# File 'lib/yard_types/types.rb', line 120 def check(obj) obj.respond_to? end |
#description ⇒ String
Returns an English phrase describing this type.
114 115 116 |
# File 'lib/yard_types/types.rb', line 114 def description "an object that responds to #{name}" end |