From: "Guy N. Hurst" Date: 2002-04-13T15:38:16+09:00 Subject: Re: not vs !, and vs && Sean Chittenden wrote: > ... > > Can someone enlighten me? How, and where, are these implemented? > > Why the difference in behavior? > > > Is puts true and (!true) > > > > intertpreted as > > (puts true) and (!true) > > > > I tried this > > puts (true and (!true) ) > > That seems like a bug... > Not a bug. p. 508, "The Ruby Way": "... if parentheses are used near a method, then Ruby will associate them with the method and expect an argument list inside. An expression is a valid argument." 'puts' is a method, so it adapts the parentheses as its own syntax for parameters. Meanwhile, 'true' is an expression and '!true' is an expression, but combining them with 'and' forms a statement. (combining them with '&&' would have formed another expression directly) You must enclose a ruby statement in parentheses to form a ruby expression. puts( (true and !true) ) puts( (not true) ) This demonstrates the slight difference between a ruby 'statement' and a ruby 'expression'. Statements must be enclosed in parentheses to form an expression, which is required for using them as an argument. Guy N. Hurst