- Perl-like global operators - especially when it comes to regexps, I
seem to keep coming back to $1 and the like.  I'd like to think there's
a better way to do this, and maybe it just needs more practise on my
part, using matcher objects or alternative syntaxes.

$~, $&, $1, etc. are local:

def bar
  p [:bar, $~, $&, $1]
  "bar" =~ /(bar)/
  p [:bar, $~, $&, $1]
end

p [:foo, $~, $&, $1]
"foo" =~ /(foo)/
p [:foo, $~, $&, $1]
bar
p [:foo, $~, $&, $1]

Thanks,

Nicholas

--
You received this message because you are subscribed to the Google Groups "Ruby or 
Rails Oceania" group.
To post to this group, send email to rails-ocea...@googlegroups.com.
To unsubscribe from this group, send email to 
rails-oceania+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to