Module: Kind::ImmutableAttributes::Reader
- Defined in:
- lib/kind/immutable_attributes/reader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attribute(name) ⇒ Object
- #attribute!(name) ⇒ Object
- #attribute?(name) ⇒ Boolean
- #with_attribute(name, value) ⇒ Object
- #with_attributes(arg) ⇒ Object
Class Method Details
.included(base) ⇒ Object
10 11 12 |
# File 'lib/kind/immutable_attributes/reader.rb', line 10 def self.included(base) base.send(:attr_reader, :attributes) end |
Instance Method Details
#attribute(name) ⇒ Object
18 19 20 |
# File 'lib/kind/immutable_attributes/reader.rb', line 18 def attribute(name) @attributes[name.to_sym] end |
#attribute!(name) ⇒ Object
22 23 24 |
# File 'lib/kind/immutable_attributes/reader.rb', line 22 def attribute!(name) @attributes.fetch(name.to_sym) end |
#attribute?(name) ⇒ Boolean
14 15 16 |
# File 'lib/kind/immutable_attributes/reader.rb', line 14 def attribute?(name) self.class.__attributes__.key?(name.to_sym) end |
#with_attribute(name, value) ⇒ Object
26 27 28 |
# File 'lib/kind/immutable_attributes/reader.rb', line 26 def with_attribute(name, value) self.class.new(@_____attrs.merge(name.to_sym => value)) end |
#with_attributes(arg) ⇒ Object
30 31 32 33 34 |
# File 'lib/kind/immutable_attributes/reader.rb', line 30 def with_attributes(arg) hash = STRICT.kind_of(::Hash, arg) self.class.new(@_____attrs.merge(hash)) end |