From: Matthew Smillie Date: 2006-06-22T03:21:28+09:00 Subject: Re: Using parenthesis/barackets in ruby On Jun 21, 2006, at 15:07, Justin Vincent wrote: > I was curious to see if ruby could be programmed with > parenthesis/barackets even though it isn't supposed to. > > To my suprise this worked... > > Is there any reason why I should not be doing this? I think the other posters pretty aptly demonstrated the readability aspect. On that front, I'll point out that you've got an extra set of parens around your if/else block: ((if...else...end)). > What is it actually doing from a code/processing point of view? The parens in your Ruby code aren't acting as block delimiters, they're just parenthesising expressions. Looking at it that way, it shouldn't be surprising that your code worked, as long as the expressions were all in the right place (which they were). What may be surprising is exactly how some expressions work in Ruby - the fact that the if...else...end block returns a value is a little odd to some people. For a specific example, take conditionals: Java: if (cond)... Ruby: if cond... The parens around the condition are required by Java. In Ruby, they're not required. Both languages allow you to parenthesise expressions, and parens don't always change the result of an expression; e.g., ((5*3)+2) == (5*3)+2 == 5*3+2. So, the following Ruby: if (a && b)... Is similar to doing this in Java: if ((a && b))... matthew smillie.