Fix inspect fallback for weird objects

This commit is contained in:
Ryan Fitzgerald 2013-11-02 15:09:39 -07:00
parent 52c18a576c
commit d703320e38
1 changed files with 20 additions and 1 deletions

View File

@ -24,10 +24,29 @@ class Pry
elsif str.include?("\e[")
["#{str}\e[0m", width]
elsif str.start_with?('#<') || str == '=' || str == '>'
["#{OBJ_COLOR}#{str}\e[0m", width]
[highlight_object_literal(str), width]
else
[CodeRay.scan(str, :ruby).term, width]
end
end
def pp(obj)
super
rescue
# 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
obj_id = obj.__id__.to_s(16) rescue 0
str = "#<#{klass}:0x#{obj_id}>"
text(Pry.color ? highlight_object_literal(str) : str)
end
private
def highlight_object_literal(object_literal)
"#{OBJ_COLOR}#{object_literal}\e[0m"
end
end
end