From 045f3fa8d52af430b4d7ac93b5f7da9bda9c9ee7 Mon Sep 17 00:00:00 2001 From: Rob Gleeson Date: Tue, 10 May 2011 06:55:46 +0100 Subject: [PATCH] Re factor the "gem-cd" command. - Add a argument check, so the command doesn't blow up. - Simplify the code. --- lib/pry/default_commands/gems.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/pry/default_commands/gems.rb b/lib/pry/default_commands/gems.rb index 9918df8a..d81ad952 100644 --- a/lib/pry/default_commands/gems.rb +++ b/lib/pry/default_commands/gems.rb @@ -28,11 +28,13 @@ class Pry output.puts "Refreshed gem cache." end - command "gem-cd", "Change working directory to specified gem's directory." do |gem_name| - require 'rubygems' - gem_spec = Gem.source_index.find_name(gem_name).first - next output.puts("Gem `#{gem_name}` not found.") if !gem_spec - Dir.chdir(File.expand_path(gem_spec.full_gem_path)) + command "gem-cd", "Change working directory to specified gem's directory." do |gem| + if gem + spec = Gem.source_index.find_name(gem).first + spec ? Dir.chdir(spec.full_gem_path) : output.puts("Gem `#{gem}` not found.") + else + output.puts 'gem-cd requires the name of a gem as an argument.' + end end