class Pry::ColorPrinter - pry-0.10.1 Documentation

# class Pry::ColorPrinter

### Constants

OBJ_COLOR

### Public Class Methods

pp(obj, out = $>, width = 79) click to toggle source

    # File lib/pry/color_printer.rb, line 15
    def self.pp(obj, out = $>, width = 79)
      q = ColorPrinter.new(out, width)
      q.guard_inspect_key { q.pp obj }
      q.flush
      out << "\n"
    end

### Public Instance Methods

pp(obj) click to toggle source
Calls superclass method

    # File lib/pry/color_printer.rb, line 33
    def pp(obj)
      super
    rescue => e
      raise if e.is_a? Pry::Pager::StopPaging

      # Read the class name off of the singleton class to provide a default
      # inspect.
      singleton = class << obj; self; end
      ancestors = Pry::Method.safe_send(singleton, :ancestors)
      klass  = ancestors.reject { |k| k == singleton }.first
      obj_id = obj.__id__.to_s(16) rescue 0
      str    = "#<#{klass}:0x#{obj_id}>"

      text highlight_object_literal(str)
    end

text(str, width = str.length) click to toggle source
Calls superclass method

    # File lib/pry/color_printer.rb, line 22
    def text(str, width = str.length)
      # Don't recolorize output with color [Issue #751]
      if str.include?("\e[")
        super "#{str}\e[0m", width
      elsif str.start_with?('#<') || str == '=' || str == '>'
        super highlight_object_literal(str), width
      else
        super CodeRay.scan(str, :ruby).term, width
      end
    end