Class: Literal::Struct
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
Attributes inherited from Structish
#attributes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Structish
#==, #[], #[]=, #deconstruct, #deconstruct_keys, #to_h
#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
Class Method Details
.attribute(name, type, special = nil, reader: :public, writer: :public, positional: false, default: nil) ⇒ Object
5
6
7
|
# File 'lib/literal/struct.rb', line 5
def attribute(name, type, special = nil, reader: :public, writer: :public, positional: false, default: nil)
super(name, type, special, reader:, writer:, positional:, default:)
end
|
.generate_literal_initializer ⇒ Object
.generate_literal_reader(attribute) ⇒ Object
.generate_literal_writer(attribute) ⇒ Object
Instance Method Details
#marshal_dump ⇒ Object
37
38
39
|
# File 'lib/literal/struct.rb', line 37
def marshal_dump
[2, @attributes, frozen?]
end
|
#marshal_load(data) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/literal/struct.rb', line 24
def marshal_load(data)
case data
when Hash @attributes = data[:attributes]
freeze if data[:frozen?]
when Array
@attributes = data[1]
freeze if data[2]
end
@literal_attributes = self.class.literal_attributes
end
|