Hacker News new | ask | show | jobs
by infraruby 3979 days ago
$~ and friends are not global:

  def f
    p $~ # => nil
    "123" =~ /\w+/
    p $~ # => #<MatchData "123">
  end

  p $~ # => nil
  "abc" =~ /\w+/
  p $~ # => #<MatchData "abc">

  f

  p $~ # => #<MatchData "abc">
1 comments

Matz himself has said he regrets putting these variables in the language, and some day they may disappear. We'll match behavior as much as possible, but they're a relic no matter how you slice it.