From: Jim Menard Date: 2002-09-26T23:54:53+09:00 Subject: Re: call for commentary: review of Ruby for a magazine (long, sorry!) "Rich Kilmer" writes: > Interesting...I usually do: > > puts "warning" unless obj > > Since obj is true if not nil > > The "if obj.nil?" may appear clearer, but 'unless obj' is easy to > grok as well. And of course this works only for cases where obj > is not a boolean value... It's ever so slightly faster, too. prompt> time ruby -e 'nope = nil; 1_000_000.times { x = 42 unless nope }' real 0m0.924s user 0m0.920s sys 0m0.000s prompt> time ruby -e 'nope = nil; 1_000_000.times { x = 42 unless nope.nil? }' real 0m0.994s user 0m0.980s sys 0m0.010s Jim -- Jim Menard, jimm@io.com, http://www.io.com/~jimm/ # A Ruby script that prints all the digits of pi (sorted). (0 .. 9).each { | i | print i while true }