From: James Edward Gray II Date: 2005-12-03T03:39:51+09:00 Subject: Re: Optimizing for Newbies On Dec 2, 2005, at 12:24 PM, Matthew Feadler wrote: > Also, these > > rolls = Array.new(2){Die.new(10).roll} > return 0 if rolls.any?{|r|r.zero?} > > are very cool. I was originally under the impression that the first > line would create a two-element array *with the same Die instance in > each element*, which would, of course, always result in a 0 total > further down the code. Nope. The block is executed to create each element. > The second line is an example of Ruby's lovely ? notation, which I've > noticed all over, but have yet to really grasp/master. Thanks for > this > example. By convention, a method ending in a ? returns a true/false answer to the question implied by the call. > A quick google > (http://www.google.com/search?hl=en&lr=&q=ruby+zip+method&btnG=Search) > doesn't give much for the zip method, so it's still a bit magical > to me. > Any references to recommend? If you have Ruby's documentation installed just feed your command-line: ri Array.zip Or you can look it up here: http://www.ruby-doc.org/core/classes/Array.html#M000391 James Edward Gray II