[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02890] Confused about '/o' in regexps

From: Dave Thomas <Dave@...>
Date: 2000-05-18 16:08:27 UTC
List: ruby-talk #2890

The /o option to a regular expression says 'do any substitutions once
only'. Thus

  for i in 0..5
    puts i if 'ab3c' =~ /ab#{i}c/
  end

will output '3', while

  for i in 0..5
    puts i if 'ab3c' =~ /ab#{i}c/o
  end

outputs nothing. So far so good.


However, I'd then expect that

  a = /ab#{c}d/;

should not evaluate the substitution immediately, but should instead
wait until I use the regexp object 'a'. Instead I get 'undefined
variable 'c''.

Am I expecting too much?


Dave

In This Thread

Prev Next