pretty_inspect (colored with CodeRay) is now the default inspect output

This commit is contained in:
John Mair 2011-06-09 02:49:35 +12:00
parent f23bb4ba8a
commit be67273e33
2 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,8 @@
# (C) John Mair (banisterfiend) 2011
# MIT License
require 'pp'
class Pry
# The default hooks - display messages when beginning and ending Pry sessions.
DEFAULT_HOOKS = {
@ -19,7 +21,7 @@ class Pry
# The default prints
DEFAULT_PRINT = proc do |output, value|
if Pry.color
output.puts "=> #{CodeRay.scan(Pry.view(value), :ruby).term}"
output.puts "=> #{CodeRay.scan(value.pretty_inspect, :ruby).term}"
else
output.puts "=> #{Pry.view(value)}"
end

View File

@ -105,12 +105,12 @@ class Pry
new(options).repl(target)
end
# A custom version of `Kernel#inspect`.
# A custom version of `Kernel#pretty_inspect`.
# This method should not need to be accessed directly.
# @param obj The object to view.
# @return [String] The string representation of `obj`.
def self.view(obj)
obj.inspect
obj.pretty_inspect
rescue NoMethodError
"unknown"
@ -122,8 +122,8 @@ class Pry
# @param max_size The maximum number of chars before clipping occurs.
# @return [String] The string representation of `obj`.
def self.view_clip(obj, max_size=60)
if Pry.view(obj).size < max_size
Pry.view(obj)
if obj.inspect.size < max_size
obj.inspect
else
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
end