class IRB::ColorPrinter
Public Class Methods
Source
# File bundled-src/irb-1.16.0/lib/irb/color_printer.rb, line 24 def initialize(out, width, colorize: true) @colorize = colorize super(out, width) end
Calls superclass method
PrettyPrint::new
Source
# File bundled-src/irb-1.16.0/lib/irb/color_printer.rb, line 8 def pp(obj, out = $>, width = screen_width, colorize: true) q = ColorPrinter.new(out, width, colorize: colorize) q.guard_inspect_key {q.pp obj} q.flush out << "\n" end
Private Class Methods
Source
# File bundled-src/irb-1.16.0/lib/irb/color_printer.rb, line 17 def screen_width Reline.get_screen_size.last rescue Errno::EINVAL # in `winsize': Invalid argument - <STDIN> 79 end
Public Instance Methods
Source
# File bundled-src/irb-1.16.0/lib/irb/color_printer.rb, line 30 def pp(obj) if String === obj # Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n" text(obj.inspect) else super end end
Calls superclass method
PP::pp
Source
# File bundled-src/irb-1.16.0/lib/irb/color_printer.rb, line 39 def text(str, width = nil) unless str.is_a?(String) str = str.inspect end width ||= str.length case str when '' when ',', '=>', '[', ']', '{', '}', '..', '...', /\A@\w+\z/ super(str, width) when /\A#</, '=', '>' super(@colorize ? Color.colorize(str, [:GREEN]) : str, width) else super(@colorize ? Color.colorize_code(str, ignore_error: true) : str, width) end end
Calls superclass method
PrettyPrint#text