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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0424fcb26d8fc260165a669fa7be1d83e41a3a8e967ad606c5eb72abb656b349
4
- data.tar.gz: 2ea8e9dc094a9612447679c7d5bebf88ac466b1c1b9a5f666d3ce5a8d0981965
3
+ metadata.gz: 88bc6a484035b5bf6320f56b55e573780d64ede93a81127a594b3f38bf4dbad8
4
+ data.tar.gz: 7813d05c00cdf651b05888c570a56d0a605d9ba26e0e6b3f6b7ee4d05c5ff4c9
5
5
  SHA512:
6
- metadata.gz: 024aac1db4f01d3528a1130817e3db22e7e413d598e99d5dc333a040057896129420193731cec1706922a5c462322809e4e6ce5de2d871f1d2492e67990b56ab
7
- data.tar.gz: c8a5b49346df275afd18502410a9e24a5806fdfdb0d31d2a7a53783edf8b592b3fe27789ca19d26f32d3937142f40c561b2a9d87ef5cff66e9aa7d05c3054cf6
6
+ metadata.gz: 8ee8693a456dfb16c72efbae23afeae3f6436b2244b0ce0c86ccfc55c605485a8147ea7e2c03c0b5fe00d9972c3d519980e8f289aade9bbedfa64b4b7c072ddb
7
+ data.tar.gz: fbc8f0d5fc535b857f1d4f54bd2e0a9b57467eaba3b1b2cacca98d92319dcc383e7c6f643ea9984700f7936a63de56d5e2b99470672bd9362963a866c3756732
data/CHANGELOG.md CHANGED
@@ -1,10 +1,15 @@
1
- ### 1.2.0 (2026/8/14)
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/6/20)
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-enum (1.2.0)
4
+ ruby-enum (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2021 Daniel Doubrovkine.
3
+ Copyright (c) 2013-2026 Daniel Doubrovkine.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
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-2021, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
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
 
@@ -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
- result = _own_enum_hash.values.map(&:value)
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 ||= if superclass < Ruby::Enum
191
- superclass.send(:_enums_by_value).merge(_own_enums_by_value)
192
- else
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby
4
4
  module Enum
5
- VERSION = '1.2.0'
5
+ VERSION = '1.2.1'
6
6
  end
7
7
  end
Binary file
@@ -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 'includes both the parent and its own redefined value in values' do
436
- expect(SubclassRedefiningParentKey.values).to eq(%w[red green crimson])
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- ruby-enum (1.2.0)
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.0)
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.0
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