Reduce method calls by passing #find_name a Regexp.
This commit is contained in:
parent
6a3fe8916a
commit
9132003887
|
@ -26,10 +26,9 @@ class Pry
|
|||
|
||||
command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |pattern|
|
||||
pattern = Regexp.new pattern.to_s, Regexp::IGNORECASE
|
||||
gems = Gem.source_index.gems.values.group_by(&:name)
|
||||
gems = Gem.source_index.find_name(pattern).group_by(&:name)
|
||||
|
||||
gems.each do |gem, specs|
|
||||
if gem =~ pattern
|
||||
specs.sort! do |a,b|
|
||||
Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
|
||||
end
|
||||
|
@ -41,7 +40,6 @@ class Pry
|
|||
output.puts "#{text.white gem} (#{versions.join ', '})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
command "req", "Requires gem(s). No need for quotes! (If the gem isn't installed, it will ask if you want to install it.)" do |*gems|
|
||||
gems = gems.join(' ').gsub(',', '').split(/\s+/)
|
||||
|
|
Loading…
Reference in New Issue