From 76d3ea84582c780b1fa8103540797fef0367f1c2 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 16 Apr 2022 22:23:34 +0900 Subject: [PATCH] Improvements to `String#each_byte` Each byte value is now retrieved inside the loop. --- mrblib/string.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mrblib/string.rb b/mrblib/string.rb index 81ddf6784..84e7530c9 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -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