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

Order candidates by load order correctly

Instead of relying just on the filename, which differs between
variations of ruby, order by position of the file in $LOADED_FEATURES.

On ruby-1.8 $LOADED_FEATURES contains relative paths, so we use
end_with?. This happily also works for absolute paths if we first
normalize with a pass of File.expand_path.
This commit is contained in:
Conrad Irwin 2013-03-23 01:15:45 -07:00
parent 53c39fdac3
commit b9ad968d33

View file

@ -327,7 +327,12 @@ class Pry
ims = all_relevant_methods_for(wrapped) ims = all_relevant_methods_for(wrapped)
@all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }. @all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }.
sort_by { |k, v| [-v.size, k] } sort_by do |path, methods|
expanded = File.expand_path(path)
load_order = $LOADED_FEATURES.index{ |file| expanded.end_with?(file) }
[-methods.size, load_order || (1.0 / 0.0)]
end
end end
# We only want methods that have a non-nil `source_location`. We also # We only want methods that have a non-nil `source_location`. We also