From: Phillip Gawlowski on
On 31.12.2009 06:32, Albert Schlef wrote:

> It works. But, I must say, it isn't as beautiful as my original plan. It
> doesn't read as English.

PS C:\Scripts> ruby .\unless.rb
/unless.rb:1: Argument error (RuntimeError)
PS C:\Scripts> ruby .\unless.rb "arg"
PS C:\Scripts> cat .\unless.rb
raise "Argument error" unless ARGV[0]
PS C:\Scripts>

I prefer it that way. :)

Works in 1.8.6 and 1.9.1, too, to my great relief.

--
Phillip Gawlowski

From: Jeff Peng on
botp :
> On Thu, Dec 31, 2009 at 10:24 AM, Albert Schlef <albertschlef(a)gmail.com> wrote:
>> Why? I thought the only diference between "or" and "||" is the
>> precedence.
>
> yes, so you can do eg
>
>>> system "pwd" or raise "no command here"
> /home/botp
> => true
>
>>> system "asdf" or raise "no command here"
> RuntimeError: no command here
>
> if you know perl, this is no surprise..
>

I know Perl, but I'm still surprised.

# perl -le 'print undef or 4'

# perl -le 'print(undef or 4)'
4

# irb
irb(main):001:0> puts nil or 4

=> 4
irb(main):002:0> puts(nil or 4)
SyntaxError: (irb):2: syntax error, unexpected keyword_or, expecting ')'
puts(nil or 4)
^
from /usr/bin/irb:12:in `<main>'



And if I "puts (nil or 4)" (there is a blank between them) will print 4.
(Just my thought,I was thinking this is a bug.)

Regards,
Jeff.

From: Seebs on
On 2009-12-31, Albert Schlef <albertschlef(a)gmail.com> wrote:
> Interesting.
>
> Why is the following a syntax error?
>
> puts (123 if true)
>
> and the following isn't?
>
> puts (123 or 456)

The if modifier has to go on the tail end of the containing complete
expression. You could say "statement", but I don't think that really
adds anything.

But that's not the same issue as why "or" doesn't work in a method argument
without extra ().

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Albert Schlef on
Seebs wrote:
> On 2009-12-31, Albert Schlef <albertschlef(a)gmail.com> wrote:
>> Interesting.
>>
>> Why is the following a syntax error?
>>
>> puts (123 if true)
>>
>> and the following isn't?
>>
>> puts (123 or 456)
>
> The if modifier has to go on the tail end of the containing complete
> expression.

Then why does the following work?

a = (123 if true)
--
Posted via http://www.ruby-forum.com/.

From: Phillip Gawlowski on
On 31.12.2009 10:31, Albert Schlef wrote:

> Then why does the following work?
>
> a = (123 if true)

Because here you do an assignment.

Ruby Appliance's Beginner VM will need a list of Ruby gotchas. :S

--
Phillip Gawlowski