class Pry::Command::Ri - pry-0.10.1 Documentation

# class Pry::Command::Ri

### Public Class Methods

new(pager, opts) click to toggle source
Calls superclass method Pry::Command.new

    # File lib/pry/commands/ri.rb, line 26
    def initialize(pager, opts)
      @pager = pager
      super opts
    end

### Public Instance Methods

formatter(io) click to toggle source

    # File lib/pry/commands/ri.rb, line 36
    def formatter(io)
      if @formatter_klass
        @formatter_klass.new
      else
        RDoc::Markup::ToAnsi.new
      end
    end

page() { |paging_text| ... } click to toggle source

    # File lib/pry/commands/ri.rb, line 30
    def page
      paging_text = StringIO.new
      yield paging_text
      @pager.page(paging_text.string)
    end

process(spec) click to toggle source

    # File lib/pry/commands/ri.rb, line 16
    def process(spec)
      # Lazily load RI
      require 'rdoc/ri/driver'

      unless defined? RDoc::RI::PryDriver

        # Subclass RI so that it formats its output nicely, and uses `lesspipe`.
        subclass = Class.new(RDoc::RI::Driver) # the hard way.

        subclass.class_eval do
          def initialize(pager, opts)
            @pager = pager
            super opts
          end
          def page
            paging_text = StringIO.new
            yield paging_text
            @pager.page(paging_text.string)
          end

          def formatter(io)
            if @formatter_klass
              @formatter_klass.new
            else
              RDoc::Markup::ToAnsi.new
            end
          end
        end

        RDoc::RI.const_set :PryDriver, subclass   # hook it up!
      end

      # Spin-up an RI insance.
      ri = RDoc::RI::PryDriver.new _pry_.pager, :use_stdout => true, :interactive => false

      begin
        ri.display_names [spec]  # Get the documentation (finally!)
      rescue RDoc::RI::Driver::NotFoundError => e
        output.puts "error: '#{e.name}' not found"
      end
    end