fixed arity problems with action.call in process_commands; where 1.8.7 was complaining if wrong number of args were passed (but 1.9.2 didnt care); now passing along correct number of args

This commit is contained in:
John Mair 2011-01-20 14:06:10 +13:00
parent 9e1e35e5f4
commit 8394004c93
1 changed files with 18 additions and 2 deletions

View File

@ -201,11 +201,27 @@ class Pry
# because procs are defined in different places (e.g 'help' in CommandBase)
# we cannot simply use `commands.opts=...`; instead we have to
# retrieve the object where the block was defined; since that is
# the `opts` method that the block will have access to.
# where the `opts` method the block will have access to is defined.
action_self = action.binding.eval('self')
action_self.opts = options
action.call(*captures)
# send the correct number of parameters to the block (to avoid
# warnings in 1.8.7)
case action.arity <=> 0
when -1
# if arity is negative then we have a *args in 1.8.7.
# In 1.9 we have default values or *args
action.call(*captures)
when 1, 0
# ensure that we get the right number of parameters;
# using values_at we pad out missing parameters with nils so
# that 1.8.7 doesn't complain about incorrect arity (1.9.2
# doesn't care)
action.call(*captures.values_at(*0..(action.arity - 1)))
end
val.clear
end
end