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... )
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.
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
( ... )
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.
Comments 4
dfd
Reply
Reply
Reply
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