From 66a403aef43dfa405516bfa6e9e5d37ffc38cf04 Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 4 May 2011 14:43:35 +1200 Subject: [PATCH] Fixed command arity warnings on ruby 1.8 --- lib/pry/command_set.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 53acbeaf..07abd22f 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -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