News for hackers. Stuff that matters.
Re:Confident Code by klochner on Thursday November 10, 2011 @03:34AM (#3219438)
Confident coding comes from understanding the language.

  Array({:foo=>1}).map{|h| h[:foo]}
  TypeError: Symbol as array index

  [{:foo=>1}].flatten.compact.map{|h| h[:foo]}
   => [1]
Re:Confident Code by avdi on Thursday November 10, 2011 @04:22AM (#3219517)
I'm not sure what you're getting at here, other than that trying to treat an array of arrays as an array of Hashes is a bad idea.
Re:Confident Code by gurkendoktor on Thursday November 10, 2011 @06:12AM (#3219704)
I think the point is that Array(h) destroys the Hash, whereas [h].flatten will leave it intact, adding another unexpected gotcha to Array().

Array's terrible friend Integer() implicitly crashed my app in production before, so found that interesting to know; not necessarily related to your talk though. :)

Re:Confident Code by vidarh on Thursday November 10, 2011 @08:29AM (#3219956)
[h].flatten on the other hand of course breaks horribly when someone decides that one of the values is meant to hold an array.