Class: Odin::Types::OdinArrayItem

Inherits:
Object
  • Object
show all
Defined in:
lib/odin/types/array_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, value: nil, fields: nil) ⇒ OdinArrayItem

Returns a new instance of OdinArrayItem.



16
17
18
19
20
21
# File 'lib/odin/types/array_item.rb', line 16

def initialize(kind:, value: nil, fields: nil)
  @kind = kind
  @value = value
  @fields = fields&.freeze
  freeze
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



6
7
8
# File 'lib/odin/types/array_item.rb', line 6

def fields
  @fields
end

#kindObject (readonly)

Returns the value of attribute kind.



6
7
8
# File 'lib/odin/types/array_item.rb', line 6

def kind
  @kind
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/odin/types/array_item.rb', line 6

def value
  @value
end

Class Method Details

.from_value(value) ⇒ Object



8
9
10
# File 'lib/odin/types/array_item.rb', line 8

def self.from_value(value)
  new(kind: :value, value: value)
end

.record(fields) ⇒ Object



12
13
14
# File 'lib/odin/types/array_item.rb', line 12

def self.record(fields)
  new(kind: :record, fields: fields)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



31
32
33
34
# File 'lib/odin/types/array_item.rb', line 31

def ==(other)
  other.is_a?(OdinArrayItem) && kind == other.kind &&
    value == other.value && fields == other.fields
end

#hashObject



37
38
39
# File 'lib/odin/types/array_item.rb', line 37

def hash
  [kind, value, fields].hash
end

#record?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/odin/types/array_item.rb', line 23

def record?
  kind == :record
end

#value?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/odin/types/array_item.rb', line 27

def value?
  kind == :value
end