From: Matthew Desmarais Date: 2006-02-10T01:38:54+09:00 Subject: Re: Ruby 1.8.4 behaviour - 2 questions Hi Jim, James B. Byrne wrote: > OS = CentOS 4.2 > Ruby = 1.8.4 > (http://dev.centos.org/centos/4.2/testing/i386/RPMS/ruby-1.8.4-1.c4.i386.rpm) > > > Problem 1. > > I am using Regexp.new() and my unit test alters behaviour for the same > regexp string depending upon whether or not any option is added to the > call. > > Thus f_nam_re = Regexp.new(f_nam_re_s) produces this: > > The passed regexp is: > ^QPCCCMR[[:digit:]]$ > The regexp used is: > /^QPCCCMR[[:digit:]]$/ > $= is: false > qpcccmr1 does not match > QPCCCMR1 matches > QPCCMMR1 does not match > qpCCCMR1 does not match > QPCCCMRC does not match > QPCCCMR1.csv does not match > QPCCCMR9 matches > XXQPCCCMR9 does not match > QPCCCMR9yyy does not match > XyZQPCCCMR3AbC does not match > > > whereas f_nam_re = Regexp.new(f_nam_re_s, ["m") produces this: > > The passed regexp is: > ^QPCCCMR[[:digit:]]$ > The regexp used is: > /^QPCCCMR[[:digit:]]$/i > $= is: false > qpcccmr1 matches > QPCCCMR1 matches > QPCCMMR1 does not match > qpCCCMR1 matches > QPCCCMRC does not match > QPCCCMR1.csv does not match > QPCCCMR9 matches > XXQPCCCMR9 does not match > QPCCCMR9yyy does not match > XyZQPCCCMR3AbC does not match > > I get the same result if I substitute "x" for "m" in the call. What is > going on? > Everything here is working correctly. If you look at the documentation for Regexp.new and pay attention to the part about specifying options you should see the correct way to accomplish what (I'm guessing) you're trying to do. > Problem 2. > > I wish to assign a float value conditional on the source being non-nil. > I thought that this construction would work; > > target_f += { source_f ? source_f : 0.00 } > The "{" character is the wrong thing to use here. You'll want to try this (assuming that target_f already has a value assigned to it): target_f += ( source_f ? source_f : 0.00 ) Hope that helps. Regards, Matthew Desmarais