From 49994f17ac7524fa6c96953c11bfd2bcefcef71f Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sun, 15 Jan 2012 15:51:04 -0800 Subject: [PATCH] Allow process() methods to take args too --- lib/pry/command.rb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 7b5fcd67..402e45fa 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -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