diff options
| author | ksss <[email protected]> | 2017-03-15 16:48:47 +0900 |
|---|---|---|
| committer | ksss <[email protected]> | 2017-03-15 16:58:28 +0900 |
| commit | 6eb02a892dbd0f0631c0362805fa995194290611 (patch) | |
| tree | 4aae9104e155d6b7ce12dba57107a585a5344fd2 /mrblib | |
| parent | f8b31a0db671b71d2794ce866b87596a09c10bf0 (diff) | |
| download | mruby-6eb02a892dbd0f0631c0362805fa995194290611.tar.gz mruby-6eb02a892dbd0f0631c0362805fa995194290611.zip | |
Use duplicated object for block args
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/string.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb index 7add360a8..5510bf6de 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -11,11 +11,12 @@ class String # ISO 15.2.10.5.15 def each_line(&block) offset = 0 - while pos = self.index("\n", offset) - block.call(self[offset, pos + 1 - offset]) + this = dup + while pos = this.index("\n", offset) + block.call(this[offset, pos + 1 - offset]) offset = pos + 1 end - block.call(self[offset, self.size - offset]) if self.size > offset + block.call(this[offset, this.size - offset]) if this.size > offset self end |
