[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: Behaviour of Enumerables reject vs. select mixed into Hash
From: Alexander Presber <aljoscha () weisshuhn ! de>
Date: 2007-06-19 11:01:57
Message-ID: A6481524-49FD-4A88-9DF6-E07072812917 () weisshuhn ! de
[Download RAW message or body]
Hello everybody,
Could you please take a look at the result of the following statements:
irb(main):001:0> a = {'foo' => 'bar', 'baz' => 'qux'}
=> {"baz"=>"qux", "foo"=>"bar"}
irb(main):002:0> a.reject{|k,v| k=='foo' }
=> {"baz"=>"qux"}
irb(main):003:0> a.select{|k,v| k=='baz' }
=> [["baz", "qux"]]
The result of the reject statement is clearly sensible: the original
hash minus the element with the key 'foo'.
But what about select? Shouldn't it return the same hash (instead of
an array of key-value pairs)?
Sincerely yours
Alexander Presber
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic