Решение на Бонус задача: ArnoldC+- от Николина Гюрова

Обратно към всички решения

Към профила на Николина Гюрова

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 14 успешни тест(а)
  • 15 неуспешни тест(а)

Код

# agh, i know it's awful
module ArnoldCPM
def self.totally_recall(&block)
definition_proxy = DefinitionProxy.new
definition_proxy.instance_eval(&block)
end
def self.printer=(printer)
@printer = printer
end
def self.printer
@printer
end
class DefinitionProxy
def initialize
@runner = ArnoldMethods.new
@functions = {}
end
def its_showtime
@run_main = true
end
def you_have_been_terminated
@run_main = false
end
def consider_that_a_divorce(what)
# or
end
def knock_knock(what)
# and
end
def let_off_some_steam_bennet(what)
# >
end
def you_are_not_you_you_are_me(what)
# ==
end
def because_im_going_to_say_please(compare)
@if_else = [compare]
@if_else[1] = []
@if_else[2] = []
@if = true
end
def bull_shit
@if = false
@else = true
end
def you_have_no_respect_for_logic
@if = false
@else = false
which = (@runner.get_var @if_else[0] != 0) ? 1 : 2
@if_else[which].each do |line|
@runner.send(line[0], line[1]) if @runner.respond_to? line[0]
end
end
def method_missing(method, *args, &_block)
if @run_main && !handle_if(method, args)
@runner.send(method, args) if @runner.respond_to? method
else
save method, args
end
method
end
def handle_if(method, args)
if @if
@if_else[1].push [method, args]
elsif @else
@if_else[2].push [method, args]
end
end
def listen_to_me_very_carefully(name)
@function = {name: name}
end
def i_need_your_clothes_your_boots_and_your_motorcycle(*args)
@function[:paramethers] = args
end
def give_these_people_air
@function[:non_void] = true
end
def hasta_la_vista_baby
@functions[@function[:name]] = @function
@function = nil
end
def do_it_now(name, *args)
result = 0
par = paramethers(name, args)
@functions[name][:body].each do |line|
@runner.send(line[0], line[1].map { |e| par[e] || e }) if @runner.respond_to? line[0]
if line[0] == :ill_be_back
result = line[1]
break
end
end
@runner.save_value result || 0
end
def paramethers(name, args)
if @functions[name][:paramethers]
Hash[*@functions[name][:paramethers].zip(args).flatten]
else
{}
end
end
def save(method, args)
if @function
@function[:body] ||= []
@function[:body].push [method, args]
end
end
end
class ArnoldMethods
def initialize
@vars = {
i_lied: 0,
no_problemo: 1
}
end
def talk_to_the_hand(what)
if what[0].is_a? Numeric
ArnoldCPM.printer.print what[0]
else
ArnoldCPM.printer.print @vars[what[0]]
end
end
def get_your_ass_to_mars(smt)
@last_value = smt[0]
end
def save_value(value)
@vars[@last_value] = get_var value[0]
end
def get_to_the_chopper(smt)
@last_variable = smt[0]
end
def here_is_my_invitation(value)
@vars[@last_variable] = get_var value[0]
end
def enough_talk(_arg)
@last_variable = nil
end
def get_var(what)
if what.is_a? Numeric
what
else
@vars[what]
end
end
def get_up(how_much)
@vars[@last_variable] += get_var how_much[0]
end
def get_down(how_much)
@vars[@last_variable] -= get_var how_much[0]
end
def youre_fired(how_much)
@vars[@last_variable] *= get_var how_much[0]
end
def he_had_to_split(how_much)
@vars[@last_variable] /= get_var how_much[0]
end
def i_let_him_go(how_much)
@vars[@last_variable] %= get_var how_much[0]
end
end
end

Лог от изпълнението

.....FFFFFFF.......F..FFFFFFF

Failures:

  1) ArnoldCPM returns 0 by default
     Failure/Error: talk_to_the_hand _invocation_result
       Double "printer" received :print with unexpected arguments
         expected: (0)
              got: (nil)
     # /tmp/d20170103-15620-loapfm/solution.rb:144:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:70:in `method_missing'
     # /tmp/d20170103-15620-loapfm/spec.rb:535:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:525:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) ArnoldCPM can take functions as arguments
     Failure/Error: do_it_now _target_function
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20170103-15620-loapfm/solution.rb:117:in `paramethers'
     # /tmp/d20170103-15620-loapfm/solution.rb:104:in `do_it_now'
     # /tmp/d20170103-15620-loapfm/spec.rb:572:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:556:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) ArnoldCPM can return functions
     Failure/Error: hasta_la_vista_baby
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20170103-15620-loapfm/solution.rb:98:in `hasta_la_vista_baby'
     # /tmp/d20170103-15620-loapfm/spec.rb:602:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:593:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  4) ArnoldCPM defines new inner functions for each function invocation
     Failure/Error: hasta_la_vista_baby
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20170103-15620-loapfm/solution.rb:98:in `hasta_la_vista_baby'
     # /tmp/d20170103-15620-loapfm/spec.rb:632:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:625:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  5) ArnoldCPM supports basic recursion
     Failure/Error: do_it_now _count, _next, _to
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20170103-15620-loapfm/solution.rb:117:in `paramethers'
     # /tmp/d20170103-15620-loapfm/solution.rb:104:in `do_it_now'
     # /tmp/d20170103-15620-loapfm/spec.rb:686:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:666:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  6) ArnoldCPM can calculate fibonacci(20) recursively
     Failure/Error: do_it_now _fibonacci, _n_minus_one
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20170103-15620-loapfm/solution.rb:117:in `paramethers'
     # /tmp/d20170103-15620-loapfm/solution.rb:104:in `do_it_now'
     # /tmp/d20170103-15620-loapfm/spec.rb:738:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:714:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  7) ArnoldCPM can use closures in very convoluted ways
     Failure/Error: do_it_now _func, _head, _tail
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20170103-15620-loapfm/solution.rb:117:in `paramethers'
     # /tmp/d20170103-15620-loapfm/solution.rb:104:in `do_it_now'
     # /tmp/d20170103-15620-loapfm/spec.rb:777:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:765:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  8) ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
     Failure/Error: talk_to_the_hand _result
       (Double "printer").print(0)
           expected: 0 times with arguments: (0)
           received: 1 time with arguments: (0)
     # /tmp/d20170103-15620-loapfm/solution.rb:144:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:70:in `method_missing'
     # /tmp/d20170103-15620-loapfm/spec.rb:206:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:192:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  9) ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
     Failure/Error: talk_to_the_hand _result
       (Double "printer").print(1)
           expected: 0 times with arguments: (1)
           received: 1 time with arguments: (1)
     # /tmp/d20170103-15620-loapfm/solution.rb:144:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:70:in `method_missing'
     # /tmp/d20170103-15620-loapfm/spec.rb:268:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:261:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  10) ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
     Failure/Error: talk_to_the_hand _result
       (Double "printer").print(11)
           expected: 0 times with arguments: (11)
           received: 1 time with arguments: (11)
     # /tmp/d20170103-15620-loapfm/solution.rb:144:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:70:in `method_missing'
     # /tmp/d20170103-15620-loapfm/spec.rb:299:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:292:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  11) ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
     Failure/Error: talk_to_the_hand _result
       (Double "printer").print(1)
           expected: 0 times with arguments: (1)
           received: 1 time with arguments: (1)
     # /tmp/d20170103-15620-loapfm/solution.rb:144:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:70:in `method_missing'
     # /tmp/d20170103-15620-loapfm/spec.rb:317:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:309:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  12) ArnoldCPM has branching mechanism that can execute if statements
     Failure/Error: expect(printer).to receive(:print).with(value_to_be_printed).ordered
       (Double "printer").print(11)
           expected: 1 time with arguments: (11)
           received: 0 times with arguments: (11)
     # /tmp/d20170103-15620-loapfm/spec.rb:878:in `block in expect_execution'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  13) ArnoldCPM has branching mechanism that can execute if-else statements
     Failure/Error: you_have_no_respect_for_logic
       (Double "printer").print(22)
           expected: 0 times with arguments: (22)
           received: 1 time with arguments: (22)
     # /tmp/d20170103-15620-loapfm/solution.rb:142:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:64:in `block in you_have_no_respect_for_logic'
     # /tmp/d20170103-15620-loapfm/solution.rb:63:in `each'
     # /tmp/d20170103-15620-loapfm/solution.rb:63:in `you_have_no_respect_for_logic'
     # /tmp/d20170103-15620-loapfm/spec.rb:367:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:361:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  14) ArnoldCPM has branching mechanism that can nest if-else statements
     Failure/Error: you_have_no_respect_for_logic
       (Double "printer").print(44)
           expected: 0 times with arguments: (44)
           received: 1 time with arguments: (44)
     # /tmp/d20170103-15620-loapfm/solution.rb:142:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:64:in `block in you_have_no_respect_for_logic'
     # /tmp/d20170103-15620-loapfm/solution.rb:63:in `each'
     # /tmp/d20170103-15620-loapfm/solution.rb:63:in `you_have_no_respect_for_logic'
     # /tmp/d20170103-15620-loapfm/spec.rb:421:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:408:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  15) ArnoldCPM has branching mechanism that considers functions truthy
     Failure/Error: you_have_no_respect_for_logic
       (Double "printer").print(22)
           expected: 0 times with arguments: (22)
           received: 1 time with arguments: (22)
     # /tmp/d20170103-15620-loapfm/solution.rb:142:in `talk_to_the_hand'
     # /tmp/d20170103-15620-loapfm/solution.rb:64:in `block in you_have_no_respect_for_logic'
     # /tmp/d20170103-15620-loapfm/solution.rb:63:in `each'
     # /tmp/d20170103-15620-loapfm/solution.rb:63:in `you_have_no_respect_for_logic'
     # /tmp/d20170103-15620-loapfm/spec.rb:460:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `instance_eval'
     # /tmp/d20170103-15620-loapfm/solution.rb:6:in `totally_recall'
     # /tmp/d20170103-15620-loapfm/spec.rb:451:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.04135 seconds
29 examples, 15 failures

Failed examples:

rspec /tmp/d20170103-15620-loapfm/spec.rb:517 # ArnoldCPM returns 0 by default
rspec /tmp/d20170103-15620-loapfm/spec.rb:540 # ArnoldCPM can take functions as arguments
rspec /tmp/d20170103-15620-loapfm/spec.rb:583 # ArnoldCPM can return functions
rspec /tmp/d20170103-15620-loapfm/spec.rb:613 # ArnoldCPM defines new inner functions for each function invocation
rspec /tmp/d20170103-15620-loapfm/spec.rb:651 # ArnoldCPM supports basic recursion
rspec /tmp/d20170103-15620-loapfm/spec.rb:695 # ArnoldCPM can calculate fibonacci(20) recursively
rspec /tmp/d20170103-15620-loapfm/spec.rb:760 # ArnoldCPM can use closures in very convoluted ways
rspec /tmp/d20170103-15620-loapfm/spec.rb:183 # ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
rspec /tmp/d20170103-15620-loapfm/spec.rb:252 # ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
rspec /tmp/d20170103-15620-loapfm/spec.rb:287 # ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
rspec /tmp/d20170103-15620-loapfm/spec.rb:304 # ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
rspec /tmp/d20170103-15620-loapfm/spec.rb:324 # ArnoldCPM has branching mechanism that can execute if statements
rspec /tmp/d20170103-15620-loapfm/spec.rb:347 # ArnoldCPM has branching mechanism that can execute if-else statements
rspec /tmp/d20170103-15620-loapfm/spec.rb:378 # ArnoldCPM has branching mechanism that can nest if-else statements
rspec /tmp/d20170103-15620-loapfm/spec.rb:441 # ArnoldCPM has branching mechanism that considers functions truthy

История (1 версия и 1 коментар)

Николина обнови решението на 28.12.2016 22:54 (преди почти 8 години)

+# agh, i know it's awful
+
+module ArnoldCPM
+ def self.totally_recall(&block)
+ definition_proxy = DefinitionProxy.new
+ definition_proxy.instance_eval(&block)
+ end
+
+ def self.printer=(printer)
+ @printer = printer
+ end
+
+ def self.printer
+ @printer
+ end
+
+ class DefinitionProxy
+ def initialize
+ @runner = ArnoldMethods.new
+ @functions = {}
+ end
+
+ def its_showtime
+ @run_main = true
+ end
+
+ def you_have_been_terminated
+ @run_main = false
+ end
+
+ def consider_that_a_divorce(what)
+ # or
+ end
+
+ def knock_knock(what)
+ # and
+ end
+
+ def let_off_some_steam_bennet(what)
+ # >
+ end
+
+ def you_are_not_you_you_are_me(what)
+ # ==
+ end
+
+ def because_im_going_to_say_please(compare)
+ @if_else = [compare]
+ @if_else[1] = []
+ @if_else[2] = []
+ @if = true
+ end
+
+ def bull_shit
+ @if = false
+ @else = true
+ end
+
+ def you_have_no_respect_for_logic
+ @if = false
+ @else = false
+ which = (@runner.get_var @if_else[0] != 0) ? 1 : 2
+ @if_else[which].each do |line|
+ @runner.send(line[0], line[1]) if @runner.respond_to? line[0]
+ end
+ end
+
+ def method_missing(method, *args, &_block)
+ if @run_main && !handle_if(method, args)
+ @runner.send(method, args) if @runner.respond_to? method
+ else
+ save method, args
+ end
+ method
+ end
+
+ def handle_if(method, args)
+ if @if
+ @if_else[1].push [method, args]
+ elsif @else
+ @if_else[2].push [method, args]
+ end
+ end
+
+ def listen_to_me_very_carefully(name)
+ @function = {name: name}
+ end
+
+ def i_need_your_clothes_your_boots_and_your_motorcycle(*args)
+ @function[:paramethers] = args
+ end
+
+ def give_these_people_air
+ @function[:non_void] = true
+ end
+
+ def hasta_la_vista_baby
+ @functions[@function[:name]] = @function
+ @function = nil
+ end
+
+ def do_it_now(name, *args)
+ result = 0
+ par = paramethers(name, args)
+ @functions[name][:body].each do |line|
+ @runner.send(line[0], line[1].map { |e| par[e] || e }) if @runner.respond_to? line[0]
+ if line[0] == :ill_be_back
+ result = line[1]
+ break
+ end
+ end
+
+ @runner.save_value result || 0
+ end
+
+ def paramethers(name, args)
+ if @functions[name][:paramethers]
+ Hash[*@functions[name][:paramethers].zip(args).flatten]
+ else
+ {}
+ end
+ end
+
+ def save(method, args)
+ if @function
+ @function[:body] ||= []
+ @function[:body].push [method, args]
+ end
+ end
+ end
+
+ class ArnoldMethods
+ def initialize
+ @vars = {
+ i_lied: 0,
+ no_problemo: 1
+ }
+ end
+
+ def talk_to_the_hand(what)
+ if what[0].is_a? Numeric
+ ArnoldCPM.printer.print what[0]
+ else
+ ArnoldCPM.printer.print @vars[what[0]]
+ end
+ end
+
+ def get_your_ass_to_mars(smt)
+ @last_value = smt[0]
+ end
+
+ def save_value(value)
+ @vars[@last_value] = get_var value[0]
+ end
+
+ def get_to_the_chopper(smt)
+ @last_variable = smt[0]
+ end
+
+ def here_is_my_invitation(value)
+ @vars[@last_variable] = get_var value[0]
+ end
+
+ def enough_talk(_arg)
+ @last_variable = nil
+ end
+
+ def get_var(what)
+ if what.is_a? Numeric
+ what
+ else
+ @vars[what]
+ end
+ end
+
+ def get_up(how_much)
+ @vars[@last_variable] += get_var how_much[0]
+ end
+
+ def get_down(how_much)
+ @vars[@last_variable] -= get_var how_much[0]
+ end
+
+ def youre_fired(how_much)
+ @vars[@last_variable] *= get_var how_much[0]
+ end
+
+ def he_had_to_split(how_much)
+ @vars[@last_variable] /= get_var how_much[0]
+ end
+
+ def i_let_him_go(how_much)
+ @vars[@last_variable] %= get_var how_much[0]
+ end
+ end
+end

Не е чак awful. (:

Като цяло нямаш добро разделение на отговорностите. Имаш два класа, единият се грижи за parse-ването, част от ArnoldC+- ключовите думи и част от контекста и друг - за останалата част. Личи си и че това разделение е изкуствено от постоянните if @runner.respond_to?.

Не става ясно кои са методи са дирекна имплементация на синтаксиса на езика и кои са някакви помощни методи.

Защо не използваш get_var в talk_to_the_hand?


Надявам се задачата да ти е била интересна и полезна. Както винаги, може да погледнеш нашето решение ако ти е интересно как ние сме решили да направим въпросното разделение.