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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4e2d75e76874aa4cce514081f4be6cd1ab19d827b8e8bb60645f4036a202402
4
- data.tar.gz: 4f2dd94d174acd1ea78b70b5063709566ba16b323d8d549221fdecaf10d184d3
3
+ metadata.gz: 04c191005baa65d6d21f1bea2bfbf8361651ab06e9c81e45cc2ab0ac7d8531e8
4
+ data.tar.gz: d66a6a791c4102e5d9347441a713e893a74e1d49efd39ee145db890ea5d9db07
5
5
  SHA512:
6
- metadata.gz: da62522c51b10954ca4dd86e4b2edcf31a13497a1ec65d169a6944d95c0c7aa6b53d8fb3d7f025ea369420ee8676a312db16c7120677f22753b61996a745bfee
7
- data.tar.gz: fc638df334bfb4ad58934d2e9736aad751465cb078a106f47758edbd7265bb9f49a48ef1d0af3d5626b14d7376c20e8be3880fdd53c17e9e26beeeb6e3bf02db
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  module DataClass
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_data_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober