Unless unless

G

Gábor SEBESTYÉN

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
 
R

Renald Buter

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
 
R

Robert Klemme

Gábor SEBESTYÉN said:
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:
false
=> niltrue
=> nilok
=> nilok
=> nilok
=> nil

Kind regards

robert
 
G

Gábor SEBESTYÉN

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


Just look carefully and mind that 'unless' is equivalent to 'if not'
Eee .. thanks ... need more coffee! :))

G=E1bor=

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,484
Latest member
JackRichard

Latest Threads

Top