Class: Literal::Structish
- Inherits:
-
Object
- Object
- Literal::Structish
show all
- Extended by:
- Attributable
- Defined in:
- lib/literal/structish.rb
Constant Summary
Attributable::Visibility
Constants included
from Monads
Monads::Either, Monads::Left, Monads::Maybe, Monads::Nothing, Monads::Result, Monads::Right, Monads::Some
Instance Attribute Summary collapse
Instance Method Summary
collapse
attribute, define_literal_methods, literal_attributes, literal_extension
Methods included from Types
#_Any, #_Array, #_Boolean, #_Callable, #_Class, #_Constraint, #_Descendant, #_Enumerable, #_Falsy, #_Float, #_Frozen, #_Hash, #_Integer, #_Interface, #_Intersection, #_Is, #_JSONData, #_Lambda, #_Map, #_Never, #_Nilable, #_Not, #_Procable, #_Range, #_Set, #_Shape, #_String, #_Symbol, #_Truthy, #_Tuple, #_Union, #_Void
Methods included from Monads
#Either, #Left, #Maybe, #Result, #Right, #Some, #Success
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6
7
8
|
# File 'lib/literal/structish.rb', line 6
def attributes
@attributes
end
|
Instance Method Details
#==(other) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/literal/structish.rb', line 12
def ==(other)
case other
when Literal::Structish
@attributes == other.attributes
else
false
end
end
|
#[](key) ⇒ Object
21
22
23
|
# File 'lib/literal/structish.rb', line 21
def [](key)
@attributes[key]
end
|
#[]=(key, value) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/literal/structish.rb', line 25
def []=(key, value)
type = @literal_attributes[key].type
if type === value
@attributes[key] = value
else
raise Literal::TypeError.expected(value, to_be_a: type)
end
end
|
#deconstruct ⇒ Object
35
36
37
|
# File 'lib/literal/structish.rb', line 35
def deconstruct
@attributes.values
end
|
#deconstruct_keys(keys) ⇒ Object
39
40
41
42
|
# File 'lib/literal/structish.rb', line 39
def deconstruct_keys(keys)
h = to_h
keys ? h.slice(*keys) : h
end
|
#to_h ⇒ Object
8
9
10
|
# File 'lib/literal/structish.rb', line 8
def to_h
@attributes.dup
end
|