[#85940] [Ruby trunk Bug#14578] Forking a child process inside of a mutex crashes the ruby interpreter — ben.govero@...
Issue #14578 has been reported by bengovero (Ben Govero).
3 messages
2018/03/05
[#86205] [Ruby trunk Feature#14618] Add display width method to String for CLI — aycabta@...
Issue #14618 has been reported by aycabta (aycabta .).
3 messages
2018/03/19
[#86366] Re: [ruby-cvs:70102] usa:r63008 (trunk): get rid of test error/failure on Windows introduced at r62955 — Eric Wong <normalperson@...>
usa@ruby-lang.org wrote:
3 messages
2018/03/28
[ruby-core:85977] [Ruby trunk Feature#14580] Hash#store accepts a block
From:
zverok.offline@...
Date:
2018-03-07 16:24:54 UTC
List:
ruby-core #85977
Issue #14580 has been updated by zverok (Victor Shepelev).
Maybe a bit off-topic, but I experimented with same ideas in [hm](https://github.com/zverok/hm) gem. It allows code like this:
```ruby
Hm(hash)
.transform_values(:a) { |val| val + 42 }
.to_h
```
After trying several approaches in production, the design decision I've made about not found keys is simply ignore them.
----------------------------------------
Feature #14580: Hash#store accepts a block
https://bugs.ruby-lang.org/issues/14580#change-70844
* Author: Soilent (Konstantin x)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Given a hash
~~~ ruby
hash = { a: 2 }
~~~
I want to update a single value in the hash:
~~~ ruby
hash[:a] = hash[:a] + 42
hash[:a] #=> 44
~~~
But instead, I would like to have a method that yields the current value for a given key and associates the block result with the key (similar to Hash#update). I think that Hash#store can be extended to support a block arg.
~~~ ruby
hash.store(:a) { |val| val + 42 }
hash[:a] #=> 44
~~~
Or it can be something like this:
~~~ ruby
hash.transform_values(:a, :b) { |val| val + 42 }
hash[:a] #=> 44
~~~
--
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>