Fixed command arity warnings on ruby 1.8

This commit is contained in:
John Mair 2011-05-04 14:43:35 +12:00
parent af7cb93d15
commit 66a403aef4
1 changed files with 13 additions and 1 deletions

View File

@ -9,14 +9,26 @@ class Pry
# different sets, aliased, removed, etc.
class CommandSet
class Command < Struct.new(:name, :description, :options, :block)
def call(context, *args)
if stub_block = options[:stub_info]
context.instance_eval(&stub_block)
else
ret = context.instance_exec(*args, &block)
ret = context.instance_exec(*correct_arg_arity(block.arity, args), &block)
ret if options[:keep_retval]
end
end
private
def correct_arg_arity(arity, args)
case arity <=> 0
when -1
args
when 1, 0
# Keep 1.8 happy
args.values_at *0..(arity - 1)
end
end
end
include Pry::Helpers::BaseHelpers