From: Phillip Gawlowski Date: 2009-12-31T19:02:31+09:00 Subject: Re: Why can't I use "or" here? On 31.12.2009 10:51, Albert Schlef wrote: > My, my, my. > > I can do this: > > a = 999 > > and I can do this: > > a = (123 if true) > > so doens't this mean that wherever I can put "999" I can also put "(123 > if true)"? Note: I'm dumbing this down as much as I can (from my limited understanding of Ruby internals), so no offense if I treat you like a child, that's not my intention, and serves to make the issue understandable. :) Since it's an if statement, you probably can. In this case, since 123 is always true, Ruby can "ignore" the "if true" bit (kinda, sorta). > In other words, why can I do this: > > puts 999 > > But I *can't* do this: > > puts (123 if true) Because puts takes an argument, not a statement (basically). The problem with computers is that they are stupid. It is obvious, to you, that you *mean* "output 123, if 123 is true". However, Ruby cannot understand intent. It sees "output (123 if true). Wait, I can't handle that, let me tell the smart guy about that, so that he can explain it really slow for me." This is an effect of multiple issues: Precedence, optimizations done by the interpreter (compiler, if you want), and the conflict of statement vs expression ("if" is a statement, "123 if true" is an expression for the purpose of this explanation). So, in a nutshell: Ruby throws up its arms, because it cannot understand what you want. That's why "puts 123 if true", "(puts 123) if true" both work, but "puts (123 if true)" doesn't. Kinda. -- Phillip Gawlowski