Skip to content

Commit

Permalink
Use duplicated object for block args
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Mar 15, 2017
1 parent f8b31a0 commit 6eb02a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mrblib/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6eb02a8

Please sign in to comment.