Newby asks: giving regexps as argument for funvtions

ts [mailto:decoux@moulon.inra.fr] patiently explains:

pigeon% irb -v
irb 0.7.4(01/05/08)
pigeon%

pigeon% irb
irb(main):001:0> str = “aaa”
"aaa"
irb(main):002:0> re = “a”
"a"
irb(main):003:0> m = %r{#{re}}.match(str)
#MatchData:0x40195ef4 irb(main):004:0>
pigeon%

I get that too but…

irb(main):001:0> def findPosRE(str, re)
irb(main):002:1> m = %r{#{re}}.match(str)
SyntaxError: compile error
(irb):2: syntax error
from (irb):2
^^^^^^^^^^^^^^^^
it errs here…

irb(main):003:0> m = %r(#{re}).match(str)
NameError: undefined local variable or method `re’ for #Object:0x2789360
from (irb):3

…so I had to enter again…

irb(main):004:0> def findPosRE(str, re)
irb(main):005:1> m = %r(#{re}).match(str)

note the parens… ^ ^
and no error…

irb(main):006:1> m.begin(0)
irb(main):007:1> end
nil
irb(main):008:0>

irb(main):001:0> def findPosRE(str, re)
irb(main):002:1> m = %r{#{re}}.match(str)
SyntaxError: compile error
(irb):2: syntax error
        from (irb):2
              ^^^^^^^^^^^^^^^^

Well, apparently this is corrected with irb 0.9 which is in 1.7.3

pigeon% irb
irb(main):001:0> def findPosRE(str, re)
irb(main):002:1> m = %r{#{re}}.match(str)
irb(main):003:1> end
nil
irb(main):004:0>
pigeon%

pigeon% irb -v
irb 0.9(02/07/03)
pigeon%

Guy Decoux