Skip to content

Instantly share code, notes, and snippets.

@rubychan
Created February 20, 2011 14:35
Show Gist options
  • Save rubychan/836007 to your computer and use it in GitHub Desktop.
Save rubychan/836007 to your computer and use it in GitHub Desktop.
diff --git a/lib/strscan.rb b/lib/strscan.rb
index c7c2b97..78dcb41 100644
--- a/lib/strscan.rb
+++ b/lib/strscan.rb
@@ -46,7 +46,7 @@ class StringScanner
end
def concat(str)
- @string << str
+ @string << StringValue(str)
self
end
alias_method :<<, :concat
@@ -78,7 +78,7 @@ class StringScanner
end
def initialize(string, dup=false)
- @string = String.new(string)
+ @string = StringValue(string)
reset_state
end
@@ -146,7 +146,7 @@ class StringScanner
end
def pre_match
- @string.substring(0, match.begin(0)) if @match
+ @string.substring(0, match.begin(0)).to_str if @match
end
def reset_state
@@ -161,7 +161,7 @@ class StringScanner
end
def rest
- @string[pos..-1]
+ @string[pos..-1].to_str
end
def rest?
@@ -207,7 +207,7 @@ class StringScanner
def string=(s)
reset_state
- @string = s
+ @string = StringValue(s)
end
def terminate
@@ -229,7 +229,7 @@ class StringScanner
return "" if len.zero?
begin
- return @string[pos, len]
+ return @string[pos, len].to_str
rescue TypeError
raise RangeError, "offset outside of possible range"
end
@@ -271,7 +271,7 @@ class StringScanner
return width unless getstr
- @string.substring(@prev_pos, width)
+ @string.substring(@prev_pos, width).to_str
end
private :_scan
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment