
Issue #20769 has been updated by nobu (Nobuyoshi Nakada). ```ruby hash.merge(image: nil) {|_, url| download(url)} hash.merge!(image: nil) {|_, url| download(url)} ``` ---------------------------------------- Feature #20769: Add `Hash#transform_value` https://bugs.ruby-lang.org/issues/20769#change-109945 * Author: seanpdoyle (Sean Doyle) * Status: Open ---------------------------------------- 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/