Robert Klemme
4/18/2009 7:33:00 AM
On 17.04.2009 20:47, Philip Müller wrote:
> On Fri, 17 Apr 2009 17:25:37 +0200, Sebastian Hungerecker
> <sepp2k@googlemail.com> wrote:
>> Example: foo = ARGV[0] or default_value).
>
> Thanks,
> ruby can be different to understand sometimes for someone coming from
> c/c++.
Yes, maybe. But if you get the hang of it you will see how useful this
is. Actually what the expression returns is a value which is "true"
equivalent, i.e. you can do things like
if a && b
puts "both set"
end
But also, and this is where the fact is handy that one of the values is
returned (the first non false and non nil in this case):
x = a || b
In C/C++ you might have to do something like
x = a == NULL ? b : a;
or maybe just
x = a ? a : b;
(My C has become a bit rusty.)
Kind regards
robert