类 IRB::ColorPrinter
常量
- METHOD_INSPECT
- METHOD_RESPOND_TO
公共类方法
pp(obj, out = $>, width = screen_width) 点击切换源代码
# File lib/irb/color_printer.rb, line 11 def pp(obj, out = $>, width = screen_width) q = ColorPrinter.new(out, width) q.guard_inspect_key {q.pp obj} q.flush out << "\n" end
私有类方法
screen_width() 点击切换源代码
# File lib/irb/color_printer.rb, line 20 def screen_width Reline.get_screen_size.last rescue Errno::EINVAL # in `winsize': Invalid argument - <STDIN> 79 end
公共实例方法
pp(obj) 点击切换源代码
调用父类方法
PP::pp
# File lib/irb/color_printer.rb, line 27 def pp(obj) if String === obj # Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n" text(obj.inspect) elsif !METHOD_RESPOND_TO.bind(obj).call(:inspect) text(METHOD_INSPECT.bind(obj).call) else super end end
text(str, width = nil) 点击切换源代码
调用父类方法
PrettyPrint#text
# File lib/irb/color_printer.rb, line 38 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(Color.colorize(str, [:GREEN]), width) else super(Color.colorize_code(str, ignore_error: true), width) end end