Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dscataglini/714005 to your computer and use it in GitHub Desktop.
Save dscataglini/714005 to your computer and use it in GitHub Desktop.
gsub! should raise runtime error on frozen strings when block is given and match is found
From 02edb2d2de470bec7bcdd030bb05ed7c7c967907 Mon Sep 17 00:00:00 2001
From: Diego Scataglini <[email protected]>
Date: Wed, 24 Nov 2010 12:11:20 -0500
Subject: [PATCH] gsub! should raise runtime error on frozen strings when block is given and match is found
---
kernel/common/string.rb | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/kernel/common/string.rb b/kernel/common/string.rb
index cce3a97..ce004f8 100644
--- a/kernel/common/string.rb
+++ b/kernel/common/string.rb
@@ -965,7 +965,9 @@ class String
last_match = nil
match = pattern.match_from self, last_end
-
+
+ raise RuntimeError, "string frozen" if block_given? && match && frozen?
+
offset = match.begin 0 if match
while match
--
1.7.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment