[#69616] [Ruby trunk - Feature #11258] add 'x' mode character for O_EXCL — cremno@...
Issue #11258 has been updated by cremno phobia.
3 messages
2015/06/16
[#69643] [Ruby trunk - Misc #11276] [RFC] compile.c: convert to use ccan/list — normalperson@...
Issue #11276 has been updated by Eric Wong.
3 messages
2015/06/17
[#69751] [Ruby trunk - Bug #11001] 2.2.1 Segmentation fault in reserve_stack() function. — kubo@...
Issue #11001 has been updated by Takehiro Kubo.
3 messages
2015/06/27
[ruby-core:69535] [Ruby trunk - Feature #9108] Hash sub-selections
From:
matz@...
Date:
2015-06-12 07:33:43 UTC
List:
ruby-core #69535
Issue #9108 has been updated by Yukihiro Matsumoto.
I prefer use of `Hash#select`, but in form of `hash.select([:foo, :bar])`, since it may consume too much stack region, besides that `hash.select(*arg)` could work differently when `arg=[]`. It would cause confusion.
Matz.
----------------------------------------
Feature #9108: Hash sub-selections
https://bugs.ruby-lang.org/issues/9108#change-52863
* Author: Tom Wardrop
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,
I seem to regularly have the requirement to work on a sub-set of key/value pairs within a hash. Ruby doesn't seem to provide a concise means of selecting a sub-set of keys from a hash. To give an example of what I mean, including how I currently achieve this:
```ruby
sounds = {dog: 'woof', cat: 'meow', mouse: 'squeak', horse: 'nay', cow: 'moo'}
domestic_sounds = sounds.select { |k,v| [:dog, :cat].include? k } #=> {dog: 'woof', cat: 'meow'}
```
I think a more concise and graceful solution to this would be to allow the Hash#[] method to take multiple arguments, returning a sub-hash, e.g.
```ruby
domestic_sounds = sounds[:dog, :cat] #=> {dog: 'woof', cat: 'meow'}
```
I had a requirement in the current project I'm working on to concatenate two values in a hash. If this proposed feature existed, I could of just done this...
```ruby
sounds[:dog, :cat].values.join #=> 'woofmeow'
```
You could do something similar for the setter also...
```ruby
sounds[:monkey, :bat] = 'screech'
sounds #=> {dog: 'woof', cat: 'meow', mouse: 'squeak', horse: 'nay', cow: 'moo', monkey: 'screech', bat: 'screech'}
```
Concise, convenient and readable. Thoughts?
--
https://bugs.ruby-lang.org/