Ruby Blocks, do or brace?

Posted by Rick DeNatale Tue, 02 Oct 2007 11:04:00 GMT

Conventional wisdom in Ruby is to use do/end to delimit blocks which contain more than one line of code, and braces for one-line blocks. I've always tended to loosely follow this advice.

Thanks to ruby-talk, I just became aware of Jim Weirich's suggestion to use braces for blocks when the value is being used, and do/end for blocks which are primarily sequences of statements. Jim actually posted this over three years ago, and Joe O'Brien brought it up more recently.

On the whole, I like this idea and will probably adopt it to tune my use of do/end vs. braces.

Read more...

Posted in ,  | Tags  | 3 comments | no trackbacks