[#108552] [Ruby master Bug#18782] Race conditions in autoload when loading the same feature with multiple threads. — "ioquatix (Samuel Williams)" <noreply@...>
Issue #18782 has been reported by ioquatix (Samuel Williams).
11 messages
2022/05/14
[ruby-core:108675] [Ruby master Bug#18793] Select and Find behave differently for hashes
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2022-05-24 19:31:24 UTC
List:
ruby-core #108675
Issue #18793 has been updated by jeremyevans0 (Jeremy Evans).
I don't think this is a bug. The behavior difference is because `Hash#each` yields an array of `[key, value]` and not `key` and `value` separately, unlike `Hash#select`.
You can get the behavior you want by using explicit block variables:
```ruby
{ 1..10 => :a, 11 .. 20 => :b }.select { |k,| k === 5 }
{ 1..10 => :a, 11 .. 20 => :b }.find { |k,| k === 5 }
```
Your code could be made to work by adding a definition for `Hash#find` that yields `key` and `value` separately, but I don't think the backwards compatibility issues with such a change are worth it.
----------------------------------------
Bug #18793: Select and Find behave differently for hashes
https://bugs.ruby-lang.org/issues/18793#change-97716
* Author: brenogazzola (Breno Gazzola)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.1
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
It seems that Hash implements select but not find, which uses the Enumerable version.
``` ruby
irb(main):009:0> { 1..10 => :a, 11 .. 20 => :b }.select { _1 === 12 }
=> {11..20=>:b}
irb(main):010:0> { 1..10 => :a, 11 .. 20 => :b }.find { _1 === 5 }
=> nil
irb(main):011:0> { 1..10 => :a, 11 .. 20 => :b }.select { p _1 }
1..10
11..20
irb(main):012:0> { 1..10 => :a, 11 .. 20 => :b }.find { p _1 }
[1..10, :a]
```
Expected Behavior:
I expected that both select and find return matches OR that neither select and find return matches
Current Behavior:
Select returns matches but find does not.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>