J
James B. Byrne
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?
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 }
but it does not. Is there a one line idiom that will assign from a
potentially nil float value obtained from a database?
I suppose that I could do this:
if !source_f then
target_f += 0.0
else
target_f += !source_f
end
But for aesthetic reasons I prefer to have this construct in a single
line.
Thanks,
Jim
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?
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 }
but it does not. Is there a one line idiom that will assign from a
potentially nil float value obtained from a database?
I suppose that I could do this:
if !source_f then
target_f += 0.0
else
target_f += !source_f
end
But for aesthetic reasons I prefer to have this construct in a single
line.
Thanks,
Jim