From 4aed2ab1c0ab8f347360f963da2807d869f8f5c6 Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Sun, 19 Jan 2014 18:00:25 -0800 Subject: [PATCH] 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. --- lib/pry/color_printer.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb index 5f804fd1..39d9a9ae 100644 --- a/lib/pry/color_printer.rb +++ b/lib/pry/color_printer.rb @@ -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}>"