1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Pass custom options to the when_started hook.

When calling Pry.start() the specified options are passed to the "when_started"
hook. This makes it possible for plugins (combined with commit
b270761efa) to specify their own options without
causing Pry to wet itself.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
This commit is contained in:
Yorick Peterse 2012-01-02 20:36:39 +01:00
parent b270761efa
commit c4f5fdda9e
2 changed files with 16 additions and 1 deletions

View file

@ -116,7 +116,12 @@ class Pry
pry_instance.backtrace = caller.tap(&:shift)
# yield the binding_stack to the hook for modification
Pry.config.hooks.exec_hook(:when_started, binding_stack = [target], pry_instance)
Pry.config.hooks.exec_hook(
:when_started,
binding_stack = [target],
options,
pry_instance
)
head, *tail = binding_stack
pry_instance.binding_stack.push(*tail)

View file

@ -171,5 +171,15 @@ describe Pry::Hooks do
@hooks.add_hook(:test_hook, :my_name3) { 3 }
@hooks.exec_hook(:test_hook).should == 3
end
it 'should take a hash containing custom options' do
number = 0
callable = proc { |options| number = options[:number] }
@hooks.add_hook(:test_with_options, :test_hook, callable)
@hooks.exec_hook(:test_with_options, :number => 10)
number.should == 10
end
end
end