[#111472] [Ruby master Bug#19274] Error installing ruby 3.2.0 on RH 8 — "aalllop (Alberto Allegue) via ruby-core" <ruby-core@...>
Issue #19274 has been reported by aalllop (Alberto Allegue).
5 messages
2022/12/28
[#111508] Data support for versions before 3.2.0 — Eustáquio Rangel via ruby-core <ruby-core@...>
I was wondering that every piece of code (gems, etc) that use the new Data =
3 messages
2022/12/29
[ruby-core:111305] [Ruby master Feature#19069] Default value assignment with `Hash.new` in block form
From:
"matz (Yukihiro Matsumoto)" <noreply@...>
Date:
2022-12-15 08:56:20 UTC
List:
ruby-core #111305
Issue #19069 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Rejected
For compatibility's sake (and to avoid extra complexity), we reject this idea.
Matz.
----------------------------------------
Feature #19069: Default value assignment with `Hash.new` in block form
https://bugs.ruby-lang.org/issues/19069#change-100672
* Author: sawa (Tsuyoshi Sawada)
* Status: Rejected
* Priority: Normal
----------------------------------------
This is a spin-out from #19063, and is a recapture of my comment https://bugs.ruby-lang.org/issues/19063#note-15.
I propose to change the behavior of `Hash.new` when it takes a block with its parameter signature absent. In such case, the evaluated value of the block should be assigned to the hash with the missing key in question (`h3` below). When the block does take parameters, then the behavior should remain as is now (`h1`, `h2` below).
```rb
h1 = Hash.new{|h, k| h[k] = "foo"}
h2 = Hash.new{|h, k| "foo"}
h3 = Hash.new{"foo"}
h1[:a] # => "foo"
h2[:a] # => "foo"
h3[:a] # => "foo"
h1 # => {:a=>"foo"}
h2 # => {}
h3 # => {:a=>"foo"}
```
This will solve a few problems. First, as discussed in #19063, many users make the mistake of writing `Hash.new([])` when they actually mean `Hash.new{|h, k| h[k] = []}`, and I suspect this is partially due to the fact that the block `{|h, k| h[k] = []}` is too long, and the users are tempted to avoid writing so. With the proposed feature introduced, the users will be encouraged to naturally write the correct form `Hash.new{[]}`.
Second, some of the more advanced users than those mentioned above still make the mistake of writing `Hash.new{foo}` when they actually mean `Hash.new{|h, k| h[k] = foo}`, and the current proposal is to let them actually be equivalent.
Third, this will resemble a similar construct `Array.new(5){[]}` and they will make a good parallel.
Indeed, there are situations where the intended behavior is to just run a routine without assigning a new key-value pair to the hash. Examples of current code may be as follows:
```rb
h4 = Hash.new{some_routine_to_take_care_of_the_missing_key_situation}
h5 = Hash.new{raise WrongKeyBlahBlahError}
```
Such blocks would need to be prepended by a parameter signature `|h, k|` in order to avoid unwanted results. I do not think such transition would be a huge pain.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/