Решение на Бонус задача: ArnoldC+- от Добромира Лозева

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

Към профила на Добромира Лозева

Резултати

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

Код

module ArnoldCPM
module DSL
def self.conditionalize(meth)
orig_meth = "#{meth}_unconditionalized"
alias_method orig_meth, meth
define_method(meth) do |*args, &block|
return if @skip_stack.any? { |s| s == true }
l = -> { public_send(orig_meth, *args, &block) }
@defining_fn ? @defining_fn.push(l) : l.call
end
end
def i_lied
0
end
def value_of(int_or_var)
int_or_var.is_a?(Integer) ? int_or_var : int_or_var[:value]
end
# TODO
def its_showtime
@skip_stack = []
end
def you_have_been_terminated
@local_store = []
end
def get_to_the_chopper(var_data)
@variable_for_assign = var_data[:name]
end
def here_is_my_invitation(number)
@variable_store[@variable_for_assign] = value_of(number)
end
def youre_fired(number)
@variable_store[@variable_for_assign] *= value_of(number)
end
def get_up(number)
@variable_store[@variable_for_assign] += value_of(number)
end
def get_down(number)
@variable_store[@variable_for_assign] -= value_of(number)
end
def he_had_to_split(number)
@variable_store[@variable_for_assign] /= value_of(number)
end
def i_let_him_go(number)
@variable_store[@variable_for_assign] %= value_of(number)
end
def let_off_some_steam_bennet(var)
@variable_store[@variable_for_assign] > value_of(var)
end
def you_are_not_you_you_are_me(var)
@variable_store[@variable_for_assign] == value_of(var)
end
def enough_talk
end
def talk_to_the_hand(number_or_var_data)
number = number_or_var_data
number = number[:value] if number.is_a?(Hash)
@printer.print number
end
def because_im_going_to_say_please(cond)
l = -> { @skip_stack.unshift(value_of(cond) == 0) }
@defining_fn ? @defining_fn.push(l) : l.call
end
def bull_shit
l = -> { @skip_stack[0] = !@skip_stack[0] }
@defining_fn ? @defining_fn.push(l) : l.call
end
def consider_that_a_divorce(var)
@variable_store[@variable_for_assign] |= value_of(var)
end
def knock_knock(var)
@variable_store[@variable_for_assign] &= value_of(var)
end
def you_have_no_respect_for_logic
l = -> { @skip_stack.shift }
@defining_fn ? @defining_fn.push(l) : l.call
end
def listen_to_me_very_carefully(var)
@defining_fn = []
@variable_store[var[:name]] = @defining_fn
@local_store = []
end
def hasta_la_vista_baby
return if @skip_stack.any? { |s| s == true }
@defining_fn = nil
end
def do_it_now(var)
var[:value].each do |l|
l.call unless @returned
end
@returned = false
end
def give_these_people_air
end
def ill_be_back(var = 0)
@variable_store[@return_target] = value_of(var)
@returned = true
end
def get_your_ass_to_mars(var)
@return_target = var[:name]
end
def i_need_your_clothes_your_boots_and_your_motorcycle(number)
end
conditionalize :value_of
conditionalize :get_to_the_chopper
conditionalize :here_is_my_invitation
conditionalize :youre_fired
conditionalize :get_up
conditionalize :get_down
conditionalize :he_had_to_split
conditionalize :i_let_him_go
conditionalize :let_off_some_steam_bennet
conditionalize :you_are_not_you_you_are_me
conditionalize :enough_talk
conditionalize :talk_to_the_hand
conditionalize :listen_to_me_very_carefully
conditionalize :do_it_now
conditionalize :ill_be_back
end
end
module ArnoldCPM
extend ArnoldCPM::DSL
def self.printer=(value)
@printer = value
end
def self.totally_recall(&block)
@variable_store = {}
@skip_stack = []
define_singleton_method(:_recall, block)
_recall
end
def self.method_missing(name, *_params, &_block)
{ name: name, value: @variable_store[name] }
end
end
ArnoldCPM.printer = Kernel

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

Finished in 0.00096 seconds
2 examples, 1 failure
/data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:200:in `flatten': can't convert Module to Array (Module#to_ary gives Hash) (TypeError)
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:200:in `full_description'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:76:in `store_computed'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:49:in `[]'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:123:in `full_description'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:76:in `store_computed'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:49:in `[]'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:41:in `block (2 levels) in delegate_to_metadata'
	from /data/rails/evans-2016/releases/20161119130633/lib/language/ruby/json_formatter.rb:22:in `example_failed'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:130:in `block in notify'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:129:in `each'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:129:in `notify'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:92:in `example_failed'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:264:in `finish'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:231:in `fail_with_exception'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:523:in `block in fail_filtered_examples'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:523:in `each'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:523:in `fail_filtered_examples'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:501:in `rescue in run'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:506:in `run'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `map'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `block in run'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:58:in `report'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:21:in `run'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
	from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'

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

Добромира обнови решението на 29.12.2016 17:46 (преди над 7 години)

+module ArnoldCPM
+ module DSL
+ def self.conditionalize(meth)
+ orig_meth = "#{meth}_unconditionalized"
+ alias_method orig_meth, meth
+
+ define_method(meth) do |*args, &block|
+ return if @skip_stack.any? { |s| s == true }
+
+ l = -> { public_send(orig_meth, *args, &block) }
+
+ @definng_fn ? @defining_fn.push(l) : l.call
+ end
+ end
+
+ def i_lied
+ 0
+ end
+
+ def value_of(int_or_var)
+ int_or_var.is_a?(Integer) ? int_or_var : int_or_var[:value]
+ end
+
+ # TODO
+ def its_showtime
+ @skip_stack = []
+ end
+
+ def you_have_been_terminated
+ @local_store = []
+ end
+
+ def get_to_the_chopper(var_data)
+ @variable_for_assign = var_data[:name]
+ end
+
+ def here_is_my_invitation(number)
+ @variable_store[@variable_for_assign] = number
+ end
+
+ def youre_fired(number)
+ @variable_store[@variable_for_assign] *= value_of(number)
+ end
+
+ def get_up(number)
+ @variable_store[@variable_for_assign] += value_of(number)
+ end
+
+ def get_down(number)
+ @variable_store[@variable_for_assign] -= value_of(number)
+ end
+
+ def he_had_to_split(number)
+ @variable_store[@variable_for_assign] /= value_of(number)
+ end
+
+ def i_let_him_go(number)
+ @variable_store[@variable_for_assign] %= value_of(number)
+ end
+
+ def let_off_some_steam_bennet(var)
+ @variable_store[@variable_for_assign] > value_of(var)
+ end
+
+ def you_are_not_you_you_are_me(var)
+ @variable_store[@variable_for_assign] == value_of(var)
+ end
+
+ def enough_talk
+ end
+
+ def talk_to_the_hand(number_or_var_data)
+ number = number_or_var_data
+ number = number[:value] if number.is_a?(Hash)
+ @printer.print number
+ end
+
+ def because_im_going_to_say_please(cond)
+ l = -> { @skip_stack.unshift(value_of(cond) == 0) }
+ @defining_fn ? @defining_fn.push(l) : l.call
+ end
+
+ def bull_shit
+ l = -> { @skip_stack[0] = !@skip_stack[0] }
+ @defining_fn ? @defining_fn.push(l) : l.call
+ end
+
+ def consider_that_a_divorce(var)
+ @variable_store[@variable_for_assign] |= value_of(var)
+ end
+
+ def knock_knock(var)
+ @variable_store[@variable_for_assign] &= value_of(var)
+ end
+
+ def you_have_no_respect_for_logic
+ l = -> { @skip_stack.shift }
+ @defining_fn ? @defining_fn.push(l) : l.call
+ end
+
+ def listen_to_me_very_carefully(var)
+ @defining_fn = []
+ @variable_store[var[:name]] = @defining_fn
+ @local_store = []
+ end
+
+ def hasta_la_vista_baby
+ return if @skip_stack.any? { |s| s == true }
+ @defining_fn = nil
+ end
+
+ def do_it_now(var)
+ var[:value].each { |l| l.call }
+ end
+
+ def give_these_people_air
+ end
+
+ def ill_be_back(var)
+ @variable_store[@return_target] = value_of(var)
+ end
+
+ def get_your_ass_to_mars(var)
+ @return_target = var[:name]
+ end
+
+ def i_need_your_clothes_your_boots_and_your_motorcycle(number)
+
+ end
+
+ conditionalize :value_of
+ conditionalize :get_to_the_chopper
+ conditionalize :here_is_my_invitation
+ conditionalize :youre_fired
+ conditionalize :get_up
+ conditionalize :get_down
+ conditionalize :he_had_to_split
+ conditionalize :i_let_him_go
+ conditionalize :let_off_some_steam_bennet
+ conditionalize :you_are_not_you_you_are_me
+ conditionalize :enough_talk
+ conditionalize :talk_to_the_hand
+ conditionalize :listen_to_me_very_carefully
+ conditionalize :do_it_now
+ end
+end
+
+module ArnoldCPM
+ extend ArnoldCPM::DSL
+
+ def self.printer=(value)
+ @printer = value
+ end
+
+ def self.totally_recall(&block)
+ @variable_store = {}
+ @skip_stack = []
+ define_singleton_method(:_recall, block)
+ _recall
+ end
+
+ def self.method_missing(name, *_params, &_block)
+ { name: name, value: @variable_store[name] }
+ end
+end
+
+ArnoldCPM.printer = Kernel

Добромира обнови решението на 29.12.2016 18:14 (преди над 7 години)

module ArnoldCPM
module DSL
def self.conditionalize(meth)
orig_meth = "#{meth}_unconditionalized"
alias_method orig_meth, meth
define_method(meth) do |*args, &block|
return if @skip_stack.any? { |s| s == true }
l = -> { public_send(orig_meth, *args, &block) }
- @definng_fn ? @defining_fn.push(l) : l.call
+ @defining_fn ? @defining_fn.push(l) : l.call
end
end
def i_lied
0
end
def value_of(int_or_var)
int_or_var.is_a?(Integer) ? int_or_var : int_or_var[:value]
end
# TODO
def its_showtime
@skip_stack = []
end
def you_have_been_terminated
@local_store = []
end
def get_to_the_chopper(var_data)
@variable_for_assign = var_data[:name]
end
def here_is_my_invitation(number)
- @variable_store[@variable_for_assign] = number
+ @variable_store[@variable_for_assign] = value_of(number)
end
def youre_fired(number)
@variable_store[@variable_for_assign] *= value_of(number)
end
def get_up(number)
@variable_store[@variable_for_assign] += value_of(number)
end
def get_down(number)
@variable_store[@variable_for_assign] -= value_of(number)
end
def he_had_to_split(number)
@variable_store[@variable_for_assign] /= value_of(number)
end
def i_let_him_go(number)
@variable_store[@variable_for_assign] %= value_of(number)
end
def let_off_some_steam_bennet(var)
@variable_store[@variable_for_assign] > value_of(var)
end
def you_are_not_you_you_are_me(var)
@variable_store[@variable_for_assign] == value_of(var)
end
def enough_talk
end
def talk_to_the_hand(number_or_var_data)
number = number_or_var_data
number = number[:value] if number.is_a?(Hash)
@printer.print number
end
def because_im_going_to_say_please(cond)
l = -> { @skip_stack.unshift(value_of(cond) == 0) }
@defining_fn ? @defining_fn.push(l) : l.call
end
def bull_shit
l = -> { @skip_stack[0] = !@skip_stack[0] }
@defining_fn ? @defining_fn.push(l) : l.call
end
def consider_that_a_divorce(var)
@variable_store[@variable_for_assign] |= value_of(var)
end
def knock_knock(var)
@variable_store[@variable_for_assign] &= value_of(var)
end
def you_have_no_respect_for_logic
l = -> { @skip_stack.shift }
@defining_fn ? @defining_fn.push(l) : l.call
end
def listen_to_me_very_carefully(var)
@defining_fn = []
@variable_store[var[:name]] = @defining_fn
@local_store = []
end
def hasta_la_vista_baby
return if @skip_stack.any? { |s| s == true }
@defining_fn = nil
end
def do_it_now(var)
var[:value].each { |l| l.call }
end
def give_these_people_air
end
def ill_be_back(var)
@variable_store[@return_target] = value_of(var)
end
def get_your_ass_to_mars(var)
@return_target = var[:name]
end
def i_need_your_clothes_your_boots_and_your_motorcycle(number)
end
conditionalize :value_of
conditionalize :get_to_the_chopper
conditionalize :here_is_my_invitation
conditionalize :youre_fired
conditionalize :get_up
conditionalize :get_down
conditionalize :he_had_to_split
conditionalize :i_let_him_go
conditionalize :let_off_some_steam_bennet
conditionalize :you_are_not_you_you_are_me
conditionalize :enough_talk
conditionalize :talk_to_the_hand
conditionalize :listen_to_me_very_carefully
conditionalize :do_it_now
+ conditionalize :ill_be_back
end
end
module ArnoldCPM
extend ArnoldCPM::DSL
def self.printer=(value)
@printer = value
end
def self.totally_recall(&block)
@variable_store = {}
@skip_stack = []
define_singleton_method(:_recall, block)
_recall
end
def self.method_missing(name, *_params, &_block)
{ name: name, value: @variable_store[name] }
end
end
ArnoldCPM.printer = Kernel

Добромира обнови решението на 29.12.2016 18:54 (преди над 7 години)

module ArnoldCPM
module DSL
def self.conditionalize(meth)
orig_meth = "#{meth}_unconditionalized"
alias_method orig_meth, meth
define_method(meth) do |*args, &block|
return if @skip_stack.any? { |s| s == true }
l = -> { public_send(orig_meth, *args, &block) }
@defining_fn ? @defining_fn.push(l) : l.call
end
end
def i_lied
0
end
def value_of(int_or_var)
int_or_var.is_a?(Integer) ? int_or_var : int_or_var[:value]
end
# TODO
def its_showtime
@skip_stack = []
end
def you_have_been_terminated
@local_store = []
end
def get_to_the_chopper(var_data)
@variable_for_assign = var_data[:name]
end
def here_is_my_invitation(number)
@variable_store[@variable_for_assign] = value_of(number)
end
def youre_fired(number)
@variable_store[@variable_for_assign] *= value_of(number)
end
def get_up(number)
@variable_store[@variable_for_assign] += value_of(number)
end
def get_down(number)
@variable_store[@variable_for_assign] -= value_of(number)
end
def he_had_to_split(number)
@variable_store[@variable_for_assign] /= value_of(number)
end
def i_let_him_go(number)
@variable_store[@variable_for_assign] %= value_of(number)
end
def let_off_some_steam_bennet(var)
@variable_store[@variable_for_assign] > value_of(var)
end
def you_are_not_you_you_are_me(var)
@variable_store[@variable_for_assign] == value_of(var)
end
def enough_talk
end
def talk_to_the_hand(number_or_var_data)
number = number_or_var_data
number = number[:value] if number.is_a?(Hash)
@printer.print number
end
def because_im_going_to_say_please(cond)
l = -> { @skip_stack.unshift(value_of(cond) == 0) }
@defining_fn ? @defining_fn.push(l) : l.call
end
def bull_shit
l = -> { @skip_stack[0] = !@skip_stack[0] }
@defining_fn ? @defining_fn.push(l) : l.call
end
def consider_that_a_divorce(var)
@variable_store[@variable_for_assign] |= value_of(var)
end
def knock_knock(var)
@variable_store[@variable_for_assign] &= value_of(var)
end
def you_have_no_respect_for_logic
l = -> { @skip_stack.shift }
@defining_fn ? @defining_fn.push(l) : l.call
end
def listen_to_me_very_carefully(var)
@defining_fn = []
@variable_store[var[:name]] = @defining_fn
@local_store = []
end
def hasta_la_vista_baby
return if @skip_stack.any? { |s| s == true }
@defining_fn = nil
end
def do_it_now(var)
- var[:value].each { |l| l.call }
+ var[:value].each do |l|
+ l.call unless @returned
+ end
+ @returned = false
end
def give_these_people_air
end
- def ill_be_back(var)
+ def ill_be_back(var = 0)
@variable_store[@return_target] = value_of(var)
+ @returned = true
end
def get_your_ass_to_mars(var)
@return_target = var[:name]
end
def i_need_your_clothes_your_boots_and_your_motorcycle(number)
end
conditionalize :value_of
conditionalize :get_to_the_chopper
conditionalize :here_is_my_invitation
conditionalize :youre_fired
conditionalize :get_up
conditionalize :get_down
conditionalize :he_had_to_split
conditionalize :i_let_him_go
conditionalize :let_off_some_steam_bennet
conditionalize :you_are_not_you_you_are_me
conditionalize :enough_talk
conditionalize :talk_to_the_hand
conditionalize :listen_to_me_very_carefully
conditionalize :do_it_now
conditionalize :ill_be_back
end
end
module ArnoldCPM
extend ArnoldCPM::DSL
def self.printer=(value)
@printer = value
end
def self.totally_recall(&block)
@variable_store = {}
@skip_stack = []
define_singleton_method(:_recall, block)
_recall
end
def self.method_missing(name, *_params, &_block)
{ name: name, value: @variable_store[name] }
end
end
ArnoldCPM.printer = Kernel

Лог от изпълнението при ръчна проверка:

.F.F..FFFFFF.......F.FFFF....

Failures:

  1) ArnoldCPM has true and false constants
     Failure/Error: talk_to_the_hand no_problemo

       #<Double "printer"> received :print with unexpected arguments
         expected: (1)
              got: (nil)
     # ./solution.rb:57:in `talk_to_the_hand'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:23:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:20:in `block (2 levels) in <top (required)>'

  2) ArnoldCPM can define and call functions with arguments
     Failure/Error: do_it_now _printing_function, 22

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     # ./solution.rb:86:in `do_it_now'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:483:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:475:in `block (2 levels) in <top (required)>'

  3) ArnoldCPM can take functions as arguments
     Failure/Error: do_it_now _invoker, _forty_two_printer, 1

     ArgumentError:
       wrong number of arguments (given 3, expected 1)
     # ./solution.rb:86:in `do_it_now'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:577:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:556:in `block (2 levels) in <top (required)>'

  4) ArnoldCPM can return functions
     Failure/Error: do_it_now _forty_two_printer

     NoMethodError:
       undefined method `each' for nil:NilClass
     # ./solution.rb:87:in `do_it_now'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:608:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:593:in `block (2 levels) in <top (required)>'

  5) ArnoldCPM defines new inner functions for each function invocation
     Failure/Error: expect(printer).to receive(:print).with(value_to_be_printed).ordered

       (Double "printer").print(0)
           expected: 1 time with arguments: (0)
           received: 0 times
     # ./spec.rb:878:in `block in expect_execution'

  6) ArnoldCPM supports basic recursion
     Failure/Error: do_it_now _count, 1, 10

     ArgumentError:
       wrong number of arguments (given 3, expected 1)
     # ./solution.rb:86:in `do_it_now'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:690:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:666:in `block (2 levels) in <top (required)>'

  7) ArnoldCPM can calculate fibonacci(20) recursively
     Failure/Error: do_it_now _fibonacci, 20

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     # ./solution.rb:86:in `do_it_now'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:753:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:714:in `block (2 levels) in <top (required)>'

  8) ArnoldCPM can use closures in very convoluted ways
     Failure/Error: do_it_now _pair, _anon

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     # ./solution.rb:86:in `do_it_now'
     # ./solution.rb:8:in `public_send'
     # ./solution.rb:8:in `block (2 levels) in conditionalize'
     # ./solution.rb:9:in `block in conditionalize'
     # ./spec.rb:796:in `block (3 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:765:in `block (2 levels) in <top (required)>'

  9) ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
     Failure/Error: consider_that_a_divorce no_problemo

     TypeError:
       nil can't be coerced into Fixnum
     # ./solution.rb:68:in `|'
     # ./solution.rb:68:in `consider_that_a_divorce'
     # ./spec.rb:203:in `block (4 levels) in <top (required)>'
     # ./solution.rb:129:in `totally_recall'
     # ./spec.rb:192:in `block (3 levels) in <top (required)>'

  10) ArnoldCPM has boolean arithmetic that given *or* between two truthy values returns the first one
      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
      # ./spec.rb:878:in `block in expect_execution'

  11) ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
      Failure/Error: knock_knock no_problemo

      TypeError:
        nil can't be coerced into Fixnum
      # ./solution.rb:71:in `&'
      # ./solution.rb:71:in `knock_knock'
      # ./spec.rb:272:in `block (4 levels) in <top (required)>'
      # ./solution.rb:129:in `totally_recall'
      # ./spec.rb:261:in `block (3 levels) in <top (required)>'

  12) ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
      Failure/Error: expect(printer).to receive(:print).with(value_to_be_printed).ordered

        (Double "printer").print(22)
            expected: 1 time with arguments: (22)
            received: 0 times
      # ./spec.rb:878:in `block in expect_execution'

  13) ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
      Failure/Error: expect(printer).to receive(:print).with(value_to_be_printed).ordered

        (Double "printer").print(0)
            expected: 1 time with arguments: (0)
            received: 0 times
      # ./spec.rb:878:in `block in expect_execution'

Finished in 0.02777 seconds (files took 0.09251 seconds to load)
29 examples, 13 failures

Failed examples:

rspec ./spec.rb:15 # ArnoldCPM has true and false constants
rspec ./spec.rb:466 # ArnoldCPM can define and call functions with arguments
rspec ./spec.rb:540 # ArnoldCPM can take functions as arguments
rspec ./spec.rb:583 # ArnoldCPM can return functions
rspec ./spec.rb:613 # ArnoldCPM defines new inner functions for each function invocation
rspec ./spec.rb:651 # ArnoldCPM supports basic recursion
rspec ./spec.rb:695 # ArnoldCPM can calculate fibonacci(20) recursively
rspec ./spec.rb:760 # ArnoldCPM can use closures in very convoluted ways
rspec ./spec.rb:183 # ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
rspec ./spec.rb:235 # ArnoldCPM has boolean arithmetic that given *or* between two truthy values returns the first one
rspec ./spec.rb:252 # ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
rspec ./spec.rb:287 # ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
rspec ./spec.rb:304 # ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations

meth 4EVER!!

In all seriousness, с изключение на няколко имена, решението ти ми харесва. Допада ми идеята с псевдо-декоратора.

ArnoldCPM не трябваше да пази друг контекст освен printer-a. Ако пусна две ArnoldC+- програми една след друга, втората ще си пази @variable_store-a на първата.


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