Improvements to String#each_byte

Each byte value is now retrieved inside the loop.
This commit is contained in:
dearblue
2022-04-16 22:23:34 +09:00
parent b352e462cf
commit 76d3ea8458
+2 -3
View File
@@ -150,10 +150,9 @@ class String
# Call the given block for each byte of +self+.
def each_byte(&block)
return to_enum(:each_byte, &block) unless block
bytes = self.bytes
pos = 0
while pos < bytes.size
block.call(bytes[pos])
while pos < bytesize
block.call(getbyte(pos))
pos += 1
end
self