From: Albert Schlef Date: 2009-12-31T14:32:42+09:00 Subject: Re: Why can't I use "or" here? botp wrote: > On Thu, Dec 31, 2009 at 10:24 AM, Albert Schlef > 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.. It *is* a surprise. In Perl, unlike in Ruby, `func(0 or 1)` *does* work.... > > as always, there are many ways in ruby, you can use || or the double > parens override. Well. it turns out there aren't that many ways in ruby. I originally tried to do the following: some_func(ARGV[0] or raise "You must provide an argument") I wish it worked. But it doesn't. So I changed it to: some_func(ARGV[0] || raise "You must provide an argument") It still didn't work. So finally I did: some_func(ARGV[0] || (raise "You must provide an argument")) It works. But, I must say, it isn't as beautiful as my original plan. It doesn't read as English. -- Posted via http://www.ruby-forum.com/.