lab42_data_class 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca6b2bccf941edcb400b3e9230d394ef867a4a37b6865f5dd76e521fdb33070f
4
- data.tar.gz: 431c61adef3873183ecba35f86c1f5397c4b8c3b9df140d09438e8e3a5d0b1da
3
+ metadata.gz: 8b6b4667c08da4511e2e4889bf35d21badc1018d7c8ce61efb66c65162c1ca0f
4
+ data.tar.gz: 0206dff912a52398e24488fd53aaac9c65ceceb3706b38bb562aac37d6d9d296
5
5
  SHA512:
6
- metadata.gz: 3f63d89d02aa4a4e2ac551ce79c6f09787ab7d7f173ef459e10a689b0c24dd1682b6d27e756534108187a113784a632adfa384858d2e553e8ca37a72d4bb1b09
7
- data.tar.gz: 8be0680e0cd43d98a9fe8bfdc8c1844ad076e65fdba2b7360f2471d2f74498dbe937fd74c456231b80066541739551e76cf58356b9fa45bdbf02a5fdab673573
6
+ metadata.gz: 23d410a7701bbdf4d175ab650e62fea5845c91d825d8346fa31955007571e2b862deccf478a831dab3e4404ef1d7f9f96018e13c672fe74a9592a534aceea186
7
+ data.tar.gz: 1e349c67fa94a4633ad5e933e755a5ab762e3b13fa28cd5a7cdfdc18a70cfe7f5190dd9d2d0ac78474a44df2dcf4010785b155b8920706cd17da98125aa55ba7
data/README.md CHANGED
@@ -235,7 +235,7 @@ And all the associated methods
235
235
  expect(box === box.new).to be_truthy
236
236
  ```
237
237
 
238
- ### Context: Behaving like a proc
238
+ ### Context: Behaving like a `Proc`
239
239
 
240
240
  It is useful to be able to filter heterogeneous lists of `DataClass` instances by means of `&to_proc`, therefore
241
241
 
@@ -255,6 +255,28 @@ Then we can filter
255
255
  expect(list.filter(&class2)).to eq([class2.new(value: 2)])
256
256
  ```
257
257
 
258
+ ### Context: Behaving like a `Hash`
259
+
260
+ We have already seen the `to_h` method, however if we want to pass an instance of `DataClass` as
261
+ keyword parameters we need an implementation of `to_hash`, which of course is just an alias
262
+
263
+ Given this keyword method
264
+ ```ruby
265
+ def extract_value(value:, **others)
266
+ [value, others]
267
+ end
268
+ ```
269
+ And this `DataClass`:
270
+ ```ruby
271
+ let(:my_class) { DataClass(value: 1, base: 2) }
272
+ ```
273
+
274
+ Then we can pass it as keyword arguments
275
+ ```ruby
276
+ expect(extract_value(**my_class.new)).to eq([1, base: 2])
277
+ ```
278
+
279
+
258
280
  # LICENSE
259
281
 
260
282
  Copyright 2022 Robert Dober robert.dober@gmail.com
@@ -92,6 +92,7 @@ module Lab42
92
92
  define_method :to_h do
93
93
  proxy.to_hash(self)
94
94
  end
95
+ alias_method :to_hash, :to_h
95
96
  end
96
97
  end
97
98
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  module DataClass
5
- VERSION = "0.3.2"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_data_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-30 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  An Immutable DataClass for Ruby