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

Allow process() methods to take args too

This commit is contained in:
Conrad Irwin 2012-01-15 15:51:04 -08:00
parent 8879dfc6de
commit 49994f17ac

View file

@ -287,6 +287,22 @@ class Pry
ret
end
# Fix the number of arguments we pass to a block to avoid arity warnings.
#
# @param Number the arity of the block
# @param Array the arguments to pass
# @return Array a (possibly shorter) array of the arguments to pass
def correct_arg_arity(arity, args)
case
when arity < 0
args
when arity == 0
[]
when arity > 0
args.values_at(*(0..(arity - 1)).to_a)
end
end
end
# A super-class for Commands that are created with a single block.
@ -307,22 +323,6 @@ class Pry
instance_exec(*correct_arg_arity(block.arity, args), &block)
end
# Fix the number of arguments we pass to a block to avoid arity warnings.
#
# @param Number the arity of the block
# @param Array the arguments to pass
# @return Array a (possibly shorter) array of the arguments to pass
def correct_arg_arity(arity, args)
case
when arity < 0
args
when arity == 0
[]
when arity > 0
args.values_at(*(0..(arity - 1)).to_a)
end
end
def help; description; end
end
@ -356,7 +356,7 @@ class Pry
output.puts slop.help
void
else
process
process(*correct_arg_arity(method(:process).arity, args))
end
end