From ca86a698969db0f9ddc9483cdd1bdc31256652d8 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Wed, 12 Jun 2019 15:47:08 -0700 Subject: [PATCH] Loop in a more rubyish way in Readme Ruby devs generally iterate using the more functional methods rather than setting up an index and mutating it. If this they are the target audience of this doc this would probably be clearer. --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cbd0fb0..eeb7932 100644 --- a/README.md +++ b/README.md @@ -168,18 +168,12 @@ pointer = instance.exports.return_string memory = instance.memory.uint8_view pointer # Read the string pointed by the pointer. -nth = 0 -string = "" - -while true - char = memory[nth] - if 0 == char - break - end +string = "" +memory.each do |char| + break if char == 0 string += char.chr - nth += 1 end puts string # Hello, World!