From: Daniel Carrera Date: 2003-07-24T08:48:14+09:00 Subject: Re: "regex literal in condition" Thanks for the explanation, but I'm not quite following. I now understand what a string literal is, but I don't quite get the problem at the if. HTH wrote: [snip] > Notice how if you do > > re = /\<\!-{19} ending left_colum -{11}\>/ > while gets > break if re > end > > then "gets" is only called once because any object instance turns true > in a boolean condition. Uhm... Let's see if I understand what you are saying. "re" here is an instance of the class Regexp. Since it's an object instance, it is interpreted as "true" by the if. Did I understand that right? What I don't follow is: - Why would that be the case? - How is a non-literal any less of an object instance than a literal. I guess that the best solution is to use ($_ =~ re). But I'd still like to understand why Ruby behaves this way. Here is another example of weird example: $ irb >> re = /hi/ >> $_ = "hello" >> puts "yes" if ($_ =~ re) => nil >> puts "yes" if re yes => nil Thanks for the help. -- Daniel Carrera | OpenPGP fingerprint: Mathematics Dept. | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88 UMD, College Park | http://www.math.umd.edu/~dcarrera/pgp.html