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 +4 -4
- data/README.md +23 -1
- data/lib/lab42/data_class/proxy.rb +1 -0
- data/lib/lab42/data_class/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6b4667c08da4511e2e4889bf35d21badc1018d7c8ce61efb66c65162c1ca0f
|
4
|
+
data.tar.gz: 0206dff912a52398e24488fd53aaac9c65ceceb3706b38bb562aac37d6d9d296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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.
|
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-
|
11
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
An Immutable DataClass for Ruby
|