Fix default inspect for Ruby 2.1

In Ruby 2.1, the ancestor list of a singleton class includes the
singleton as the first element, so we need to filter it out.
This commit is contained in:
Ryan Fitzgerald 2014-01-19 18:00:25 -08:00
parent add29398f0
commit 4aed2ab1c0
1 changed files with 3 additions and 2 deletions

View File

@ -37,8 +37,9 @@ class Pry
# Read the class name off of the singleton class to provide a default
# inspect.
eig = class << obj; self; end
klass = Pry::Method.safe_send(eig, :ancestors).first
singleton = class << obj; self; end
ancestors = Pry::Method.safe_send(singleton, :ancestors)
klass = ancestors.reject { |k| k == singleton }.first
obj_id = obj.__id__.to_s(16) rescue 0
str = "#<#{klass}:0x#{obj_id}>"