Class: Literal::Array::Generic

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/literal/array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Generic

Returns a new instance of Generic.



7
8
9
# File 'lib/literal/array.rb', line 7

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/literal/array.rb', line 11

def type
  @type
end

Instance Method Details

#===(value) ⇒ Object



19
20
21
# File 'lib/literal/array.rb', line 19

def ===(value)
  Literal::Array === value && Literal.subtype?(value.__type__, @type)
end

#>=(other) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/literal/array.rb', line 23

def >=(other)
  case other
  when Literal::Array::Generic
    Literal.subtype?(other.type, @type)
  else
    false
  end
end

#coerce(value) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/literal/array.rb', line 36

def coerce(value)
  case value
  when self
    value
  when Array
    Literal::Array.new(value, type: @type)
  end
end

#inspectObject



32
33
34
# File 'lib/literal/array.rb', line 32

def inspect
  "Literal::Array(#{@type.inspect})"
end

#new(*value) ⇒ Object Also known as: []



13
14
15
# File 'lib/literal/array.rb', line 13

def new(*value)
  Literal::Array.new(value, type: @type)
end

#to_procObject



45
46
47
# File 'lib/literal/array.rb', line 45

def to_proc
  method(:coerce).to_proc
end