Class: Contraction::TypedContainer

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

Direct Known Subclasses

SizedContainer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_type, type_list) ⇒ TypedContainer

Returns a new instance of TypedContainer.



108
109
110
111
# File 'lib/parser/type_parser.rb', line 108

def initialize(class_type, type_list)
  @type_list  = type_list
  @class_name = class_type
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



106
107
108
# File 'lib/parser/type_parser.rb', line 106

def class_name
  @class_name
end

#type_listObject (readonly)

Returns the value of attribute type_list.



106
107
108
# File 'lib/parser/type_parser.rb', line 106

def type_list
  @type_list
end

Instance Method Details

#check(thing) ⇒ Object



117
118
119
120
# File 'lib/parser/type_parser.rb', line 117

def check(thing)
  return false if !class_name.nil? && !class_name.check(thing)
  thing.all? { |v| type_list.works_as_a? v }
end

#works_as_a?(thing) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/parser/type_parser.rb', line 113

def works_as_a?(thing)
  type_list.works_as_a? thing
end