Class: Typical::Type::List

Inherits:
Typical::Type show all
Defined in:
lib/typical/type/list.rb

Direct Known Subclasses

Array, Hash, Set

Instance Attribute Summary collapse

Attributes inherited from Typical::Type

#type

Instance Method Summary collapse

Methods inherited from Typical::Type

#nullable?, of, #prominent_type, #types, #|

Constructor Details

#initialize(*objects) ⇒ List

Returns a new instance of List.



8
9
10
11
# File 'lib/typical/type/list.rb', line 8

def initialize(*objects)
  @storage = new_storage
  load_from_objects(objects)
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



6
7
8
# File 'lib/typical/type/list.rb', line 6

def storage
  @storage
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
# File 'lib/typical/type/list.rb', line 29

def ==(other)
  other.is_a?(self.class) && values == other.values
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/typical/type/list.rb', line 25

def empty?
  values.empty?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/typical/type/list.rb', line 33

def eql?(other)
  super && @storage == other.storage
end

#hashObject



37
38
39
# File 'lib/typical/type/list.rb', line 37

def hash
  [super, @storage].hash
end

#inspectObject



41
42
43
# File 'lib/typical/type/list.rb', line 41

def inspect
  "#<Type:#{type} [#{values.inspect}]>"
end

#normalizeObject



13
14
15
# File 'lib/typical/type/list.rb', line 13

def normalize
  self.class.new.tap { |copy| copy.values = values.normalize(false) }
end

#valuesObject



17
18
19
# File 'lib/typical/type/list.rb', line 17

def values
  @storage[:values]
end

#values=(values) ⇒ Object



21
22
23
# File 'lib/typical/type/list.rb', line 21

def values=(values)
  @storage[:values] = values
end