John Maclean wrote:

> Simple script that spits out "Ruby" if it was typed at stdin. What's the error, see below.
> #!/usr/bin/env ruby
> 
> while gets
>   if /Ruby/
>     print 
>   end 
> end
> 
> jayeola@tp20$ ruby fx/ruby/p22 
> fx/ruby/p22:4: warning: regex literal in condition

Just what Ruby says: The above ought to be the same as this:

re = /Ruby/
while gets
   if re
     print
   end
end

It's just if obj and if obj executes the code whenever it is not false 
or nil.

The correct way to do this:

while line = gets
   if /Ruby/.match(line) then
     print line
   end
end

-- 
http://flgr.0x42.net/