[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Unless unless

Gábor Sebestyén

6/17/2005 8:44:00 AM

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?

Gábor



3 Answers

Renald Buter

6/17/2005 8:48:00 AM

0

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

6/17/2005 8:49:00 AM

0

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

6/17/2005 8:54:00 AM

0


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ábor