From: David A. Black on
Hi --

On Thu, 31 Dec 2009, Albert Schlef wrote:

> 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.

It's not supposed to; it's supposed to read as Ruby :-) I wouldn't
make too much of the English-likeness. I think of it more as an
emergent thing than as a style guideline.


David

--
David A. Black
Senior Developer, Cyrus Innovation Inc.
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com

From: Phillip Gawlowski on
On 01.01.2010 12:15, David A. Black wrote:

> I wouldn't worry about that idiom ceasing to work :-)

In open source software (or Free Software), I *do* worry about API
stability, or rather compatibility of version X to version Y.

I've been burned by Linux kernel changes far too often to *not* worry. :(

Mind, I'm not averse to change, even change that sheds weight and thus
breaks backwards compatibility, but I prefer it to be in a major
release, rather than a minor version.

Very different issue from the OP, though.

--
Phillip Gawlowski

From: David A. Black on
Hi --

On Fri, 1 Jan 2010, Phillip Gawlowski wrote:

> On 01.01.2010 12:15, David A. Black wrote:
>
>> I wouldn't worry about that idiom ceasing to work :-)
>
> In open source software (or Free Software), I *do* worry about API stability,
> or rather compatibility of version X to version Y.

So do I, but I think we're safe on this particular one. That's all I
mean.


David

--
David A. Black
Senior Developer, Cyrus Innovation Inc.
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com

From: botp on
On Thu, Dec 31, 2009 at 3:13 PM, Jeff Peng <jeffpeng(a)netzero.net> wrote:
> I know Perl, but I'm still surprised.
>
> # perl -le 'print undef or 4'
>
> # perl -le 'print(undef or 4)'
> 4

do not be surprise, ruby opted for the former case since it is more
common, and therefore has relegated the "or/and" ops w very low
precedence level (and ergo different fr their sibling ops "||/&&")

in other words, if you see a method like

>> puts 1,2 or 4
1
2
=> 4

it actually means

>> puts( 1,2) or 4
1
2
=> 4

and if you write a statement like

>> puts( 1,2 or 4)

ruby will err for you
but friendly enough to allow you to by (re)emphasizing...

so maybe you meant

>> puts( 1, (2 or 4))


best regards
-botp