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.



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

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

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



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

def storage
  @storage
end

Instance Method Details

#==(other) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  values.empty?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  [super, @storage].hash
end

#inspectObject



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

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

#normalizeObject



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

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

#valuesObject



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

def values
  @storage[:values]
end

#values=(values) ⇒ Object



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

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