News for hackers. Stuff that matters.
Re:JRuby 9000 released by rugmug5 on Wednesday July 22, 2015 @04:36PM (#9932142)
You really shouldn't be relying on globals anyway. Using $1 etc. is a serious code smell. It shouldn't by definition be threadsafe in any event. The only way that would work would be if you rely on the threads not actually running at the same time as an implementation detail of the MRI.
Re:JRuby 9000 released by infraruby on Wednesday July 22, 2015 @04:50PM (#9932223)
$~ 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">
Re:JRuby 9000 released by headius on Wednesday July 22, 2015 @05:45PM (#9932538)
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.
Re:JRuby 9000 released by cheald on Wednesday July 22, 2015 @04:49PM (#9932209)
Well, it's fair to say "it works in MRI"; $1 being frame-local and thread-local is an exception to the rule, but it is How It Works. JRuby should behave similarly, full stop.
Re:JRuby 9000 released by Freaky on Wednesday July 22, 2015 @05:44PM (#9932531)
They're what MRI calls "svars", or special variables. They're thread and scope-local, and regardless of your feelings towards them, they're still used all over the place, in old and new code alike.