From: Robert Dober Date: 2007-06-21T17:16:36+09:00 Subject: Re: Behaviour of Enumerables reject vs. select mixed into Hash On 6/21/07, Trans wrote: > > > On Jun 20, 3:21 pm, Alexander Presber wrote: > > 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)? > > I have to concur. I've never liked that. You'd think there'd be some > way to have Enumerable act in accordance with the class it is > effecting, rather then dropping to the "LCD" --an array. So do I, Do you happen to have some remedies for this in Facets? I am trying to unify such things in my library, but I am not building something even close to Factes[1], however if you are interested in some peaces let me know. Cheers Robert [1] because than I would just use Facets which is really great, but I want a small library and I want magic dot notation, which are liked by few only :( R. > > T. > > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw