Skip to content

Instantly share code, notes, and snippets.

@kronos
Created February 5, 2010 02:56
Show Gist options
  • Save kronos/295450 to your computer and use it in GitHub Desktop.
Save kronos/295450 to your computer and use it in GitHub Desktop.
From 82cf87a1338bfbbd9d78aa44d1bf6f951aa8adfe Mon Sep 17 00:00:00 2001
From: Ivan Samsonov <hronya@gmail.com>
Date: Fri, 5 Feb 2010 05:59:26 +0300
Subject: [PATCH] Repair $~ variable
---
kernel/common/string.rb | 1 +
kernel/delta/kernel.rb | 2 +-
spec/ruby/core/string/rpartition_spec.rb | 5 +++++
3 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/kernel/common/string.rb b/kernel/common/string.rb
index c811f0e..132b613 100644
--- a/kernel/common/string.rb
+++ b/kernel/common/string.rb
@@ -1297,6 +1297,7 @@ class String
def rpartition(pattern)
if pattern.kind_of? Regexp
if m = pattern.search_region(self, 0, size, false)
+ Rubinius::VariableScope.of_sender.last_match = m
[m.pre_match, m[0], m.post_match]
end
else
diff --git a/kernel/delta/kernel.rb b/kernel/delta/kernel.rb
index 2f7dbe3..1d6d708 100644
--- a/kernel/delta/kernel.rb
+++ b/kernel/delta/kernel.rb
@@ -76,7 +76,7 @@ module Kernel
# Same as $!, for any accesses we might miss.
# HACK. I doubt this is correct, because of how it will be called.
- get = proc { Regex.last_match }
+ get = proc { Regexp.last_match }
Rubinius::Globals.set_hook(:$~, get, nil)
get = proc { ARGV }
diff --git a/spec/ruby/core/string/rpartition_spec.rb b/spec/ruby/core/string/rpartition_spec.rb
index a1c2a69..30d480e 100644
--- a/spec/ruby/core/string/rpartition_spec.rb
+++ b/spec/ruby/core/string/rpartition_spec.rb
@@ -16,6 +16,11 @@ ruby_version_is '1.8.7' do
"hello!".rpartition(/l./).should == ["hel", "lo", "!"]
end
+ it "affects $~" do
+ matched_string = "hello!".rpartition(/l./)[1]
+ matched_string.should == $~[0]
+ end
+
ruby_bug "redmine #1510", '1.9.1' do
it "converts its argument using :to_str" do
find = mock('l')
--
1.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment