Class: YardTypes::DuckType

Inherits:
Type
  • Object
show all
Defined in:
lib/yard_types/types.rb

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

Attributes inherited from Type

#name

Instance Method Summary collapse

Methods inherited from Type

for, #to_s

Constructor Details

#initialize(name) ⇒ 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

#messageString (readonly)


105
106
107
# File 'lib/yard_types/types.rb', line 105

def message
  @message
end

Instance Method Details

#check(obj) ⇒ Boolean


120
121
122
# File 'lib/yard_types/types.rb', line 120

def check(obj)
  obj.respond_to? message
end

#descriptionString


114
115
116
# File 'lib/yard_types/types.rb', line 114

def description
  "an object that responds to #{name}"
end