Module: Strict::Value
Class Method Summary
collapse
Instance Method Summary
collapse
#inspect, #pretty_print, #to_h
Class Method Details
.included(mod) ⇒ Object
5
6
7
|
# File 'lib/strict/value.rb', line 5
def self.included(mod)
Attributes::GeneratedMethods.install_on(mod, writable: false)
end
|
Instance Method Details
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
13
14
15
16
|
# File 'lib/strict/value.rb', line 13
def deconstruct_keys(keys)
attributes = Attributes::Instance.attribute_values(self)
keys ? attributes.slice(*keys) : attributes
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
18
19
20
21
22
23
24
|
# File 'lib/strict/value.rb', line 18
def eql?(other)
return false unless self.class.equal?(other.class)
self.class.strict_attributes.all? do |attribute|
public_send(attribute.name).eql?(other.public_send(attribute.name))
end
end
|
#hash ⇒ Integer
27
28
29
30
31
32
33
34
|
# File 'lib/strict/value.rb', line 27
def hash
value_class = self.class
components = [value_class]
value_class.strict_attributes.each do |attribute|
components << public_send(attribute.name)
end
components.hash
end
|
#with(**attributes) ⇒ self
9
10
11
|
# File 'lib/strict/value.rb', line 9
def with(**attributes)
self.class.new(**Attributes::Instance.attribute_values(self), **attributes)
end
|