This is stupid: Hash#select vs reject
A little consistency would be nice…
1 2 |
{1=>1, 2=>2, 3=>3}.reject {|key, value| key != 1 } # => {1=>1}
{1=>1, 2=>2, 3=>3}.select {|key, value| key == 1 } # => [[1, 1]]
|
A little consistency would be nice…
1 2 |
{1=>1, 2=>2, 3=>3}.reject {|key, value| key != 1 } # => {1=>1}
{1=>1, 2=>2, 3=>3}.select {|key, value| key == 1 } # => [[1, 1]]
|
August 16, 2007 at 11:47 AM
I’m most likely missing something, but how is this inconsistent?
August 16, 2007 at 11:48 AM
reject/select are the converse of each other, they should have the same return type. I think hash is correct, I have seen arguments that array would be the correct type. Either way, they should be the same.