mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Don't call Ruby 2.4+'s String#pretty_print
https://github.com/ruby/irb/commit/89bcf107be
This commit is contained in:
parent
e019dd24df
commit
278522f053
2 changed files with 10 additions and 0 deletions
|
@ -21,6 +21,15 @@ module IRB
|
|||
end
|
||||
end
|
||||
|
||||
def pp(obj)
|
||||
if obj.is_a?(String)
|
||||
# Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n"
|
||||
text(obj.inspect)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def text(str, width = nil)
|
||||
unless str.is_a?(String)
|
||||
str = str.inspect
|
||||
|
|
|
@ -34,6 +34,7 @@ module TestIRB
|
|||
end
|
||||
{
|
||||
1 => "#{BLUE}#{BOLD}1#{CLEAR}\n",
|
||||
"a\nb" => %[#{RED}#{BOLD}"#{CLEAR}#{RED}a\\nb#{CLEAR}#{RED}#{BOLD}"#{CLEAR}\n],
|
||||
IRBTestColorPrinter.new('test') => "#{GREEN}#<struct TestIRB::TestColorPrinter::IRBTestColorPrinter#{CLEAR} a#{GREEN}=#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{RED}test#{CLEAR}#{RED}#{BOLD}\"#{CLEAR}#{GREEN}>#{CLEAR}\n",
|
||||
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",
|
||||
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",
|
||||
|
|
Loading…
Reference in a new issue