From: Mark Hubbart Date: 2004-05-02T06:33:21+09:00 Subject: Re: Ruby Newbie (ooh, that rhymes!) - When do I use do/end, when {}? On May 1, 2004, at 1:54 PM, Glenn wrote: > I've read the User Guide and other docs on the net, but I'm a little > unsure as to whether I can ALWAYS substitute the DO/END with curly > brackets for a block? For example, I've only ever seen referenced to > hash definitions using curlies. What's the rule here? Is it purely > down to preference? While there is some amount of preference involved, there is a general rule that most Ruby programmers (and matz, I believe) agree on: brackets for one-line blocks, do...end for longer blocks. ie: 5.times {|n| puts n } 5.times do |n| print "bingo! " if n == 3 puts n end There are skirmishes sometimes between people who like to use all brackets all the time, and those who use the above method. :) But this is the most common way, and you'll find it mostly like that in the standard library. HTH, --Mark