aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-01-04 19:38:22 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2021-01-04 20:14:31 -0800
commit515d6b47ad9e0933c94c9dc4c1f296ef2d555934 (patch)
tree7a06961e52fee0a176a6d35b95ecd393d234fed2 /lib
parent451b45605161a801e8a1e3c53e02d74de82a096a (diff)
downloadruby-515d6b47ad9e0933c94c9dc4c1f296ef2d555934.tar.gz
[ruby/irb] Stringify when a non-object is passed to PP#text
If a nested object is passed to #pp, it may be sometimes passed to the #text method as an object without being stringified. This is fixed on the Ruby main repository; https://github.com/ruby/ruby/commit/433a3be86a811de0b4adbb92e054ee3a6fc6b4d8 but it was a bug of Ripper so still needs this workaround for using irb as a gem on Ruby 3.0.0 or earlier. Co-authored-by: k0kubun <takashikkbn@gmail.com> https://github.com/ruby/irb/commit/8d13df22ee
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/color_printer.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb
index 187c337187..3667ef16fe 100644
--- a/lib/irb/color_printer.rb
+++ b/lib/irb/color_printer.rb
@@ -10,7 +10,12 @@ module IRB
out
end
- def text(str, width = str.length)
+ def text(str, width = nil)
+ unless str.is_a?(String)
+ str = str.inspect
+ end
+ width ||= str.length
+
case str
when /\A#</, '=', '>'
super(Color.colorize(str, [:GREEN]), width)