And the devil don't care if you're a fish or you're a stick...

Oct 09, 2008 23:04

I'm going to change tacks tonight and post publicly to write about something which pissed me off one time too many tonight. Next time it'll be back to the yawning, bitching and bawling, I promise ( Read more... )

Leave a comment

Comments 4

anonymous October 10 2008, 06:14:52 UTC
My guess: it's a bug in either select or reject. Try to file a bug report and see what comes out of it?

dfd

Reply

fromeo October 12 2008, 15:58:37 UTC
I would, but the documentation actually states that it works that way, so someone must have sat down and thought "Hash#select should return an array of two-element arrays." You could use Array#assoc or Array#rassoc to work with it almost as if it's a hash, or use inject to re-construct the hash, but it just seems weird.

Reply


wokboy October 11 2008, 10:36:48 UTC
I have no idea why writers of the library did what they did, maybe they had a good reason. The output isn't wrong per se... just confusing. Out of curiosity, when you do "a.reject" does it mutate the original a hashtbl? If it does, that may explain why they offer an alternative ( ... )

Reply


fromeo October 12 2008, 16:11:45 UTC
They do have a "fold," it's called "inject" in Ruby, I think because that's what it was called in Smalltalk. I find it extremely handy to index a list by some attribute of the elements in the list, to group elements by some criteria, or logically-AND-or-OR a list of conditions.

IIRR, Ruby's blocks are almost closures, but have some subtle difference that makes them not quite that. I don't really remember what the definition of a closure is, so I'm not sure what that difference is. Handy is what they are.

Reply


Leave a comment

Up