Skip to content

Commit 6eb02a8

Browse files
committed
Use duplicated object for block args
1 parent f8b31a0 commit 6eb02a8

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

mrblib/string.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ class String
1111
# ISO 15.2.10.5.15
1212
def each_line(&block)
1313
offset = 0
14-
while pos = self.index("\n", offset)
15-
block.call(self[offset, pos + 1 - offset])
14+
this = dup
15+
while pos = this.index("\n", offset)
16+
block.call(this[offset, pos + 1 - offset])
1617
offset = pos + 1
1718
end
18-
block.call(self[offset, self.size - offset]) if self.size > offset
19+
block.call(this[offset, this.size - offset]) if this.size > offset
1920
self
2021
end
2122

0 commit comments

Comments
 (0)