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

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

View file

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