mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
updated Pry.view_clip() to call #inspect on Numerics, Strings and Symbols, added tests for this. Also added new CLIPPED_PRINT printer (using Pry.view_clip), perhaps useful for enormous objects)
This commit is contained in:
parent
af11439d55
commit
375dfbe380
3 changed files with 53 additions and 31 deletions
|
@ -45,6 +45,11 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
# useful when playing with truly enormous objects
|
||||
CLIPPED_PRINT = proc do |output, value|
|
||||
output.puts "=> #{Pry.view_clip(value)}"
|
||||
end
|
||||
|
||||
# Will only show the first line of the backtrace
|
||||
DEFAULT_EXCEPTION_HANDLER = proc do |output, exception|
|
||||
output.puts "#{exception.class}: #{exception.message}"
|
||||
|
@ -69,6 +74,7 @@ class Pry
|
|||
end
|
||||
}
|
||||
]
|
||||
|
||||
# Deal with the ^D key being pressed, different behaviour in
|
||||
# different cases:
|
||||
# 1) In an expression - behave like `!` command (clear input buffer)
|
||||
|
|
|
@ -106,11 +106,13 @@ class Pry
|
|||
elsif TOPLEVEL_BINDING.eval('self') == obj
|
||||
# special case for 'main' object :)
|
||||
obj.inspect
|
||||
elsif [String, Numeric, Symbol].any? { |v| v === obj } && obj.inspect.length <= max_length
|
||||
obj.inspect
|
||||
else
|
||||
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
|
||||
end
|
||||
|
||||
rescue
|
||||
rescue RescuableException
|
||||
"unknown"
|
||||
end
|
||||
|
||||
|
|
|
@ -1142,6 +1142,20 @@ describe Pry do
|
|||
end
|
||||
end
|
||||
|
||||
describe "given the a Numeric, String or Symbol object" do
|
||||
[1, 2.0, -5, "hello", :test].each do |o|
|
||||
it "returns the #inspect of the special-cased immediate object: #{o}" do
|
||||
Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
|
||||
end
|
||||
end
|
||||
|
||||
# only testing with String here :)
|
||||
it "returns #<> format of the special-cased immediate object if #inspect is longer than maximum" do
|
||||
o = "o" * (VC_MAX_LENGTH + 1)
|
||||
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /String:0x.*?/
|
||||
end
|
||||
end
|
||||
|
||||
describe "given an object with an #inspect string as long as the maximum specified" do
|
||||
it "returns the #<> format of the object (never use inspect)" do
|
||||
o = Object.new
|
||||
|
|
Loading…
Reference in a new issue