Skip to content

Commit 89bcf10

Browse files
committed
Don't call Ruby 2.4+'s String#pretty_print
1 parent ecc8233 commit 89bcf10

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/irb/color_printer.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ def screen_width
2121
end
2222
end
2323

24+
def pp(obj)
25+
if obj.is_a?(String)
26+
# Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n"
27+
text(obj.inspect)
28+
else
29+
super
30+
end
31+
end
32+
2433
def text(str, width = nil)
2534
unless str.is_a?(String)
2635
str = str.inspect

test/irb/test_color_printer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_color_printer
3434
end
3535
{
3636
1 => "#{BLUE}#{BOLD}1#{CLEAR}\n",
37+
"a\nb" => %[#{RED}#{BOLD}"#{CLEAR}#{RED}a\\nb#{CLEAR}#{RED}#{BOLD}"#{CLEAR}\n],
3738
IRBTestColorPrinter.new('test') => "#{GREEN}#<struct TestIRB::TestColorPrinter::IRBTestColorPrinter#{CLEAR} a#{GREEN}=#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{RED}test#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}\n",
3839
Ripper::Lexer.new('1').scan => "[#{GREEN}#<Ripper::Lexer::Elem:#{CLEAR} on_int@1:0 END token: #{RED}#{BOLD}\"#{CLEAR}#{RED}1#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}]\n",
3940
Class.new{define_method(:pretty_print){|q| q.text("[__FILE__, __LINE__, __ENCODING__]")}}.new => "[#{CYAN}#{BOLD}__FILE__#{CLEAR}, #{CYAN}#{BOLD}__LINE__#{CLEAR}, #{CYAN}#{BOLD}__ENCODING__#{CLEAR}]\n",

0 commit comments

Comments
 (0)