Velocity Reviews > Ruby > Unless unless

# Unless unless

Gábor SEBESTYÉN
Guest
Posts: n/a

 06-17-2005
I have this very simple example:

a =3D 1
b =3D nil
puts a.nil?
puts b.nil?
puts "ok" unless a.nil? and b.nil?

Running it results these:

false
true
ok

Why the third answer is ok? Unless false and true =3D> false ..
Clue?

G=E1bor

Renald Buter
Guest
Posts: n/a

 06-17-2005
On 17:44 Fri 17 Jun , G?bor SEBESTY?N wrote:
> I have this very simple example:
>
> a = 1
> b = nil
> puts a.nil?
> puts b.nil?
> puts "ok" unless a.nil? and b.nil?
>
> Running it results these:
>
> false
> true
> ok
>
> Why the third answer is ok? Unless false and true => false ..

Just look carefully and mind that 'unless' is equivalent to 'if not'
a.nil? => false
b.nil? => true
false and true => false
if not false => if true

Regards,

Renald

Robert Klemme
Guest
Posts: n/a

 06-17-2005
Gábor SEBESTYÉN wrote:
> I have this very simple example:
>
> a = 1
> b = nil
> puts a.nil?
> puts b.nil?
> puts "ok" unless a.nil? and b.nil?
>
> Running it results these:
>
> false
> true
> ok
>
> Why the third answer is ok? Unless false and true => false ..
> Clue?

That's standard logic. Maybe this helps:

>> a = 1

=> 1
>> b = nil

=> nil
>> puts a.nil?

false
=> nil
>> puts b.nil?

true
=> nil
>> puts "ok" unless a.nil? and b.nil?

ok
=> nil
>> a.nil? and b.nil?

=> false
>> puts "ok" unless false

ok
=> nil
>> puts "ok" if not false

ok
=> nil

Kind regards

robert

Gábor SEBESTYÉN
Guest
Posts: n/a

 06-17-2005
--Apple-Mail-1--1042675108
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=ISO-8859-1;
format=flowed

On 2005.06.17., at 10:48, Renald Buter wrote:

> Just look carefully and mind that 'unless' is equivalent to 'if not'
>

Eee .. thanks ... need more coffee! )

G=E1bor=

--Apple-Mail-1--1042675108--