Class: Contraction::TypeList

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/type_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(things) ⇒ TypeList

Returns a new instance of TypeList.



68
69
70
# File 'lib/parser/type_parser.rb', line 68

def initialize(things)
  @types = things.flatten
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



67
68
69
# File 'lib/parser/type_parser.rb', line 67

def types
  @types
end

Instance Method Details

#check(thing) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/parser/type_parser.rb', line 76

def check(thing)
  # The only time that we need to match all instead of any is with
  # duck-typing, so we just special-case it here.
  if types.all? { |t| t.is_a? Contraction::DuckType }
    return types.all? { |t| t.check(thing) }
  else
    return types.any? { |t| t.check(thing) }
  end
end

#sizeObject



86
87
88
# File 'lib/parser/type_parser.rb', line 86

def size
  types.size
end

#works_as_a?(thing) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/parser/type_parser.rb', line 72

def works_as_a?(thing)
  types.any? { |t| t.works_as_a? thing }
end