Hi,
I can't find anything in Programming Ruby to suggest why zero is treated as
true, as happens in lines and 12 in the following toy program. Is it
perhaps because Ruby has no boolean type, so zero gets converted to a
string, or something? Aside from an explantion, can you cite a relevant
page in the Thomas&Hunt book?
Thanks in advance,
Richard
def count_exes(l)
n = l.count "x"
end
DATA.each_line do |line|
print line.chomp
if n = count_exes(line) then print "\t(#{n} exes in line) [Pgm line 7]"
end
if (n = count_exes(line)) > 0 then print "\t(additional note for
ex-lines)" end
puts
end
puts "0 is " + (0?"true":"false") + " [Pgm line 12]"
__END__
Two 'xx's
Three 'xxx's
No ekses
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.687 / Virus Database: 448 - Release Date: 5/16/2004