Unless unless

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

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

···

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

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

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

Gábor

···

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

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