Actions
Bug #15443
closedHash#slide with infinite range gives unexpective result
Description
{ 1 => :a, 2 => :b, 3 => :c }.slice(2..)
returns {}
. I had expected that it retuns {2=>:b, 3=>:c}
instead.
Updated by Hanmac (Hans Mackowiak) over 5 years ago
Hash#slice
takes an array of keys via *keys
each parameter is checked as a key in the Hash
{ 1 => :a, 2 => :b, 3 => :c }.slice(2, 3) #=> { 2 => :b, 3 => :c }
{ 1 => :a, 2 => :b, 3 => :c }.slice([2, 3]) #=> {} [2,3] is not a key in Hash
There is no special Rule for Range, that's why you get {}
Updated by mame (Yusuke Endoh) over 5 years ago
- Status changed from Open to Rejected
Not a bug but a spec of Hash#slice
. Consider the case where the keys are a range:
{ (1..) => :a, (2..) => :b, (3..) => :c }.slice(2..) #=> {2..=>:b}
Note that this behavior is not specific to endless range:
{ 1 => :a, 2 => :b, 3 => :c }.slice(2..3) #=> {}
Updated by ana06 (Ana Maria Martinez Gomez) over 5 years ago
It sound reasonable ;) this can be closed then
Actions
Like0
Like0Like0Like0