lab42_data_class 0.1.1 → 0.1.2
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 +21 -0
- data/lib/lab42/data_class/proxy.rb +10 -0
- data/lib/lab42/data_class/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04c191005baa65d6d21f1bea2bfbf8361651ab06e9c81e45cc2ab0ac7d8531e8
|
4
|
+
data.tar.gz: d66a6a791c4102e5d9347441a713e893a74e1d49efd39ee145db890ea5d9db07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ee5d308afdb75b72840846a7c968d95693204f9db441e8c20825c239c3a9895f0ebfb0cf49e8c2fef5c5e31b79c858cee837c91281a7b48b888451dc6f49e50
|
7
|
+
data.tar.gz: 3f170816817a20cd00827d87bf4257cfa7a8e8c748f0a46be64ca30ea3d4533c1d9af9a3192676abf3ea9119b8f6c5a7ef69144c89ee1a1dd71bd165bc0d8af1
|
data/README.md
CHANGED
@@ -110,6 +110,27 @@ And we have a nice name for our instances
|
|
110
110
|
expect(DC.new.class.name).to eq("DC")
|
111
111
|
```
|
112
112
|
|
113
|
+
### Context: Equality
|
114
|
+
|
115
|
+
Given two instances of a DataClass
|
116
|
+
```ruby
|
117
|
+
let(:data_class) { DataClass :a }
|
118
|
+
let(:instance1) { data_class.new(a: 1) }
|
119
|
+
let(:instance2) { data_class.new(a: 1) }
|
120
|
+
```
|
121
|
+
Then they are equal in the sense of `==` and `eql?`
|
122
|
+
```ruby
|
123
|
+
expect(instance1).to eq(instance2)
|
124
|
+
expect(instance2).to eq(instance1)
|
125
|
+
expect(instance1 == instance2).to be_truthy
|
126
|
+
expect(instance2 == instance1).to be_truthy
|
127
|
+
```
|
128
|
+
But not in the sense of `equal?`, of course
|
129
|
+
```ruby
|
130
|
+
expect(instance1).not_to be_equal(instance2)
|
131
|
+
expect(instance2).not_to be_equal(instance1)
|
132
|
+
```
|
133
|
+
|
113
134
|
# LICENSE
|
114
135
|
|
115
136
|
Copyright 2022 Robert Dober robert.dober@gmail.com
|
@@ -48,6 +48,15 @@ module Lab42
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def _define_eql?
|
52
|
+
->(*) do
|
53
|
+
define_method :== do |other|
|
54
|
+
other.is_a?(self.class) &&
|
55
|
+
to_h == other.to_h
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
51
60
|
def _define_initializer
|
52
61
|
proxy = self
|
53
62
|
->(*) do
|
@@ -72,6 +81,7 @@ module Lab42
|
|
72
81
|
def _define_methods
|
73
82
|
klass.module_eval(&_define_to_h)
|
74
83
|
klass.module_eval(&_define_merge)
|
84
|
+
klass.module_eval(&_define_eql?)
|
75
85
|
klass.module_eval(&block) if block
|
76
86
|
end
|
77
87
|
|