Accept code as block in ActionsHandler#evaluate

This commit is contained in:
Thibault Jouan 2015-04-21 11:34:01 +00:00
parent e8dacfa4ac
commit cc66b6a760
2 changed files with 12 additions and 3 deletions

View File

@ -10,8 +10,12 @@ module Uh
@env, @events = env, events @env, @events = env, events
end end
def evaluate code def evaluate code = nil, &block
instance_eval &code if code
instance_exec &code
else
instance_exec &block
end
end end
def quit def quit

View File

@ -6,10 +6,15 @@ module Uh
subject(:actions) { described_class.new env, events } subject(:actions) { described_class.new env, events }
describe '#evaluate' do describe '#evaluate' do
it 'evaluates given code' do it 'evaluates code given as Proc argument' do
expect { actions.evaluate proc { throw :action_code } } expect { actions.evaluate proc { throw :action_code } }
.to throw_symbol :action_code .to throw_symbol :action_code
end end
it 'evaluates code given as block' do
expect { actions.evaluate { throw :action_code } }
.to throw_symbol :action_code
end
end end
describe '#quit' do describe '#quit' do