From: Brian Candler Date: 2005-07-19T18:14:38+09:00 Subject: Re: What does this construct mean? On Tue, Jul 19, 2005 at 02:50:54AM +0900, Casper wrote: > I guess two reasons that I had difficult figuring out are (1) Ruby > allows executable stuff to go where I expect to see declarations, but > moreover (2) Ruby allows method calls to have their arguments > delineated with or without parentheses. In particular, I don't > understand the why you would want this. Is there a good motivation to > allow it? Probably because of the first program people see: puts "Hello, world!" versus: puts("Hello, world!") However, even this simple example highlights a problem. Insert a space between puts and ( and you get a warning: $ ruby -we 'puts ("Hello")' -e:1: warning: (...) interpreted as grouped expression Hello $ ruby -we 'puts ("Hello","world")' -e:1: warning: don't put space before argument parentheses Hello world Even though (a,b,c) is not a valid expression when standing alone, the Ruby interpreter has difficulty deciding whether (a) is an expression wrapped in parentheses, or a method call argument list wrapped in parentheses. To see where it makes a difference, try these: $ ruby -e 'puts ("a"), ("b")' $ ruby -e 'puts("a"), ("b")' $ ruby -e 'puts (3+4).abs' $ ruby -e 'puts(3+4).abs' I think the space-sensitive behaviour is driven by this last case: i.e. that "method1 (expr).method2" should be parsed as "method1( (expr).method2 )" whereas "method1(expr).method2" is "(method1(expr)).method2" Regards, Brian.