[2019][ruby] simplify getting the parameter mode
change wvvvltyuzlnwtyqtypotspwvvpptlmty
commit 33aebed01c466438777c17afe6715f257b3a3fb9
author Alpha Chen <alpha@kejadlen.dev>
date
parent tvpulmsp
diff --git a/2019/ruby/computer.rb b/2019/ruby/computer.rb
index 911ad23..4111c41 100644
--- a/2019/ruby/computer.rb
+++ b/2019/ruby/computer.rb
@@ -95,11 +95,12 @@ class Computer
         @pc += 1
 
         n = opcode.arity - 3
-        args = (0...n).zip(T.must(instruction[0..2]).reverse.chars.map(&:to_i)).map {|i, mode|
+        args = (0...n).map {|i|
+          mode = instruction[2-i] { ?0 }
           value = @memory.fetch(@pc + i) || 0
           mode = case mode
-                 when 0 then Mode::Position
-                 when 1 then Mode::Immediate
+                 when ?0 then Mode::Position
+                 when ?1 then Mode::Immediate
                  else fail "unexpected mode: #{mode}"
                  end
           Parameter.new(mode, value)