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

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

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