l43_open_object 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/l43/open_object.rb +10 -4
  3. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22850fd9e80553bee925ca5a0c43c6deb8468bad02a9d54a04defece69881565
4
- data.tar.gz: ac0a953bcfa8226a563fd4bab9fc23191bd22aa649e8f4216eec5a71473faf1d
3
+ metadata.gz: 9976c1247191d0a07f77df9ba0b986cd57412458c1167a7a8751f82c03fce094
4
+ data.tar.gz: d65d9275e3cdd6b756d913918310487764bb60cb8a43617183fbf7f020b3857c
5
5
  SHA512:
6
- metadata.gz: 3d605403bd858a5b718b478bac3878ec30eeb7d74c08e0167bff02038bb93aa56af40f9ffa7f5d35e3c229772f6a644060d7001a72604a6d0dcd8c4a0005aec5
7
- data.tar.gz: 9205bd62f6aa011fc1f3846f0f29f08135602ead4e7d8f12a116940401acfb87cad44b8c00ae9d3291b32bea662b2c154f7e5df77dd955fb66645a8f8ae3668c
6
+ metadata.gz: b280373d581088fc015c9d460dd806a5bfb0c3049cf274582453bccb53951523b95320bdef551e273ff00e5a04f50f0e47a964585438a7a29cd17c52cc94f9b1
7
+ data.tar.gz: 5aee83609062b79c9fa3947c1126c22a45351ba816dba24af83ba6779a9e77487d670feec520d01ec91a3a5a9ba2d29ecc8222369c83298368ed34af34d797a2
@@ -2,7 +2,7 @@
2
2
 
3
3
  module L43
4
4
  module OpenObject
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  def attributes(*atts, **defaults)
8
8
  attr_reader(*atts)
@@ -24,17 +24,23 @@ module L43
24
24
  instance_variable_set("@#{key}", value)
25
25
  end
26
26
  _init if respond_to?(:_init)
27
+ freeze
27
28
  end
28
29
 
29
30
  define_method :to_h do |*|
30
31
  first = atts.inject Hash.new do |h, attribute|
31
32
  h.update(attribute => send(attribute))
32
33
  end
33
- defaults.keys.inject first do |h, attribute|
34
- h.update(attribute => send(attribute))
35
- end
34
+ defaults.keys.inject first do |h, attribute|
35
+ h.update(attribute => send(attribute))
36
+ end
36
37
  end
37
38
  alias_method :deconstruct_keys, :to_h
39
+
40
+ define_method :update do |**kwds|
41
+ new_values = to_h.merge(**kwds)
42
+ self.class.new(**new_values)
43
+ end
38
44
  end
39
45
  end
40
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: l43_open_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -13,7 +13,9 @@ dependencies: []
13
13
  description: |-
14
14
  When using the class method `attributes` in a class you get:
15
15
  - an initialize method with attributes as kwd params and the respective defaults
16
+ - immutable instances
16
17
  - a to_h method using all attributes
18
+ - an update method to create new imutable instances
17
19
  - a destruct_keys method aliased to to_h for pattern matching
18
20
  email: robert.dober@gmail.com
19
21
  executables: []