[#119637] Behavior of raising from rescue blocks when multiple rescue blocks exist — Rodrigo Rosenfeld Rosas via ruby-core <ruby-core@...>
Hello, I couldn't find any documentation about the subject, so I thought
3 messages
2024/10/29
[ruby-core:119458] [Ruby master Feature#20769] Add `Hash#transform_value`
From:
"matz (Yukihiro Matsumoto) via ruby-core" <ruby-core@...>
Date:
2024-10-05 06:13:17 UTC
List:
ruby-core #119458
Issue #20769 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Feedback
I don't see the real-world use-case for the proposed method.
Matz.
----------------------------------------
Feature #20769: Add `Hash#transform_value`
https://bugs.ruby-lang.org/issues/20769#change-110078
* Author: seanpdoyle (Sean Doyle)
* Status: Feedback
----------------------------------------
Add `Hash#transform_value` as a specialized, key-specific version of [Hash#transform_values](https://docs.ruby-lang.org/en/3.3/Hash.html#method-i-transform_values).
```ruby
hash = { image: "https://example.com/image.jpg" }
mutated_hash = hash.transform_value(:image) { |url| download(url) }
hash # => { image: "https://example.com/image.jpg" }
mutated_hash # => { image: File<...> }
hash.transform_value!(:image) { |url| download(url) }
hash # => { image: File<...> }
```
Similar value transformation can be achieved through variable assignment and direct mutation:
```ruby
hash = { image: "https://example.com/image.jpg" }
hash.merge(image: download(hash[:image]))
hash[:image] = download(hash[:image])
```
While simple and currently supported, it requires a local variable (and therefore poses some challenges when chaining other methods) and repeats the Hash key in both the reading and writing portions of the code.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/