ruby-enum 1.2.0 → 1.2.1
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/CHANGELOG.md +7 -2
- data/Gemfile.lock +1 -1
- data/LICENSE.md +1 -1
- data/README.md +1 -1
- data/lib/ruby-enum/enum.rb +11 -13
- data/lib/ruby-enum/version.rb +1 -1
- data/pkg/ruby-enum-1.2.0.gem +0 -0
- data/spec/ruby-enum/enum_spec.rb +9 -2
- data/spec_i18n/Gemfile.lock +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88bc6a484035b5bf6320f56b55e573780d64ede93a81127a594b3f38bf4dbad8
|
|
4
|
+
data.tar.gz: 7813d05c00cdf651b05888c570a56d0a605d9ba26e0e6b3f6b7ee4d05c5ff4c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ee8693a456dfb16c72efbae23afeae3f6436b2244b0ce0c86ccfc55c605485a8147ea7e2c03c0b5fe00d9972c3d519980e8f289aade9bbedfa64b4b7c072ddb
|
|
7
|
+
data.tar.gz: fbc8f0d5fc535b857f1d4f54bd2e0a9b57467eaba3b1b2cacca98d92319dcc383e7c6f643ea9984700f7936a63de56d5e2b99470672bd9362963a866c3756732
|
data/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
### 1.2.
|
|
1
|
+
### 1.2.1 (2026/08/15)
|
|
2
|
+
|
|
3
|
+
* [#62](https://github.com/dblock/ruby-enum/issues/62): Fixed `values`, `value?` and `key` to not return a superclass' overridden value when a subclass redefines a key, matching the behavior of `to_h` and other methods - [@dblock](https://github.com/dblock).
|
|
4
|
+
* [#64](https://github.com/dblock/ruby-enum/pull/64): Updated copyright year to 2026 - [@dblock](https://github.com/dblock).
|
|
5
|
+
|
|
6
|
+
### 1.2.0 (2026/08/14)
|
|
2
7
|
|
|
3
8
|
* [#49](https://github.com/dblock/ruby-enum/issues/49): Fixed `NoMethodError` on `keys`, `values`, `key?`, `value?`, `key`, `value`, `to_h`, `parse` and `each` when a subclass defines no enums of its own - [@dblock](https://github.com/dblock).
|
|
4
9
|
* [#49](https://github.com/dblock/ruby-enum/issues/49): `keys`, `key?`, `value?`, `key`, `value`, `to_h`, `parse` and `each` now include enums defined in a superclass, matching the existing behavior of `values` - [@dblock](https://github.com/dblock).
|
|
5
10
|
* [#61](https://github.com/dblock/ruby-enum/pull/61): Document performance overhead in README, add `rake benchmark:basic` - [@dblock](https://github.com/dblock).
|
|
6
11
|
|
|
7
|
-
### 1.1.0 (2026/
|
|
12
|
+
### 1.1.0 (2026/06/20)
|
|
8
13
|
|
|
9
14
|
* [#56](https://github.com/dblock/ruby-enum/pull/56): Fix `DuplicateKeyError` when the enum class is reloaded - [@flvrone](https://github.com/flvrone).
|
|
10
15
|
* [#54](https://github.com/dblock/ruby-enum/pull/54): Add support for Ruby 4.0 - [@dblock](https://github.com/dblock).
|
data/Gemfile.lock
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
|
@@ -357,7 +357,7 @@ You're encouraged to contribute to ruby-enum. See [CONTRIBUTING](CONTRIBUTING.md
|
|
|
357
357
|
|
|
358
358
|
## Copyright and License
|
|
359
359
|
|
|
360
|
-
Copyright (c) 2013-
|
|
360
|
+
Copyright (c) 2013-2026, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
|
|
361
361
|
|
|
362
362
|
This project is licensed under the [MIT License](LICENSE.md).
|
|
363
363
|
|
data/lib/ruby-enum/enum.rb
CHANGED
|
@@ -124,15 +124,9 @@ module Ruby
|
|
|
124
124
|
_enum_hash.values.map(&:key)
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
# Returns all enum values.
|
|
127
|
+
# Returns all enum values, including those defined in a superclass.
|
|
128
128
|
def values
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if superclass < Ruby::Enum
|
|
132
|
-
superclass.values + result
|
|
133
|
-
else
|
|
134
|
-
result
|
|
135
|
-
end
|
|
129
|
+
_enum_hash.values.map(&:value)
|
|
136
130
|
end
|
|
137
131
|
|
|
138
132
|
# Iterate over all enumerated values, including those defined in a superclass.
|
|
@@ -186,12 +180,16 @@ module Ruby
|
|
|
186
180
|
# Returns the enums-by-value hash for this class merged with all of its
|
|
187
181
|
# superclasses, with values defined in this class taking precedence over
|
|
188
182
|
# those inherited from a superclass.
|
|
183
|
+
#
|
|
184
|
+
# Derived from _enum_hash (keyed by key) rather than merged directly by
|
|
185
|
+
# value, so that a superclass' stale value for a key overridden in this
|
|
186
|
+
# class doesn't linger, e.g. when a subclass redefines a key with a new
|
|
187
|
+
# value, the superclass' old value should no longer be found via value?
|
|
188
|
+
# or key.
|
|
189
189
|
def _enums_by_value
|
|
190
|
-
@_enums_by_value ||=
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
_own_enums_by_value
|
|
194
|
-
end
|
|
190
|
+
@_enums_by_value ||= _enum_hash.each_with_object({}) do |(_key, enum), hash|
|
|
191
|
+
hash[enum.value] = enum
|
|
192
|
+
end
|
|
195
193
|
end
|
|
196
194
|
|
|
197
195
|
def upper?(s)
|
data/lib/ruby-enum/version.rb
CHANGED
|
Binary file
|
data/spec/ruby-enum/enum_spec.rb
CHANGED
|
@@ -432,8 +432,15 @@ describe Ruby::Enum do
|
|
|
432
432
|
expect(SubclassRedefiningParentKey.to_h).to eq(RED: 'crimson', GREEN: 'green')
|
|
433
433
|
end
|
|
434
434
|
|
|
435
|
-
it
|
|
436
|
-
expect(SubclassRedefiningParentKey.values).to eq(%w[
|
|
435
|
+
it "does not include the parent's overridden value, only its own redefined value, in values" do
|
|
436
|
+
expect(SubclassRedefiningParentKey.values).to eq(%w[crimson green])
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
it "does not recognize the parent's overridden value via value? or key" do
|
|
440
|
+
expect(SubclassRedefiningParentKey.value?('red')).to be false
|
|
441
|
+
expect(SubclassRedefiningParentKey.key('red')).to be_nil
|
|
442
|
+
expect(SubclassRedefiningParentKey.value?('crimson')).to be true
|
|
443
|
+
expect(SubclassRedefiningParentKey.key('crimson')).to eq :RED
|
|
437
444
|
end
|
|
438
445
|
|
|
439
446
|
it "the parent class' own value is unaffected" do
|
data/spec_i18n/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ..
|
|
3
3
|
specs:
|
|
4
|
-
ruby-enum (1.2.
|
|
4
|
+
ruby-enum (1.2.1)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: http://rubygems.org/
|
|
@@ -39,7 +39,7 @@ CHECKSUMS
|
|
|
39
39
|
rspec-expectations (3.13.5)
|
|
40
40
|
rspec-mocks (3.13.8)
|
|
41
41
|
rspec-support (3.13.7)
|
|
42
|
-
ruby-enum (1.2.
|
|
42
|
+
ruby-enum (1.2.1)
|
|
43
43
|
|
|
44
44
|
BUNDLED WITH
|
|
45
45
|
4.0.6
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-enum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Doubrovkine
|
|
@@ -43,6 +43,7 @@ files:
|
|
|
43
43
|
- pkg/ruby-enum-0.8.0.gem
|
|
44
44
|
- pkg/ruby-enum-0.9.0.gem
|
|
45
45
|
- pkg/ruby-enum-1.1.0.gem
|
|
46
|
+
- pkg/ruby-enum-1.2.0.gem
|
|
46
47
|
- ruby-enum.gemspec
|
|
47
48
|
- spec/ruby-enum/enum/case_spec.rb
|
|
48
49
|
- spec/ruby-enum/enum_spec.rb
|