Sha256: abc53d501e84562d8435278bc4d9cad160c8034b159d26c0054aea7579fe423a

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

require 'pry/commands/show_info'

class Pry
  class Command::ShowSource < Command::ShowInfo
    match 'show-source'
    group 'Introspection'
    description 'Show the source for a method or class.'

    banner <<-'BANNER'
      Usage:   show-source [OPTIONS] [METH|CLASS]
      Aliases: $, show-method

      Show the source for a method or class. Tries instance methods first and then
      methods by default.

      show-source hi_method
      show-source hi_method
      show-source Pry#rep     # source for Pry#rep method
      show-source Pry         # for Pry class
      show-source Pry -a      # for all Pry class definitions (all monkey patches)
      show-source Pry.foo -e  # for class of the return value of expression `Pry.foo`
      show-source Pry --super # for superclass of Pry (Object class)

      https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
    BANNER

    def options(opt)
      opt.on :e, :eval, "evaluate the command's argument as a ruby expression and show the class its return value"
      super(opt)
    end

    def process
      if opts.present?(:e)
        obj = target.eval(args.first)
        self.args = Array.new(1) { Module === obj ? obj.name : obj.class.name }
      end
      super
    end

    # The source for code_object prepared for display.
    def content_for(code_object)
      Code.new(code_object.source, start_line_for(code_object)).
        with_line_numbers(use_line_numbers?)
    end
  end

  Pry::Commands.add_command(Pry::Command::ShowSource)
  Pry::Commands.alias_command 'show-method', 'show-source'
  Pry::Commands.alias_command '$', 'show-source'
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
whos_dated_who-0.1.0 vendor/bundle/gems/pry-0.10.0/lib/pry/commands/show_source.rb
whos_dated_who-0.0.1 vendor/bundle/gems/pry-0.10.0/lib/pry/commands/show_source.rb
pry-0.10.0 lib/pry/commands/show_source.rb
pry-0.10.0-i386-mswin32 lib/pry/commands/show_source.rb
pry-0.10.0-i386-mingw32 lib/pry/commands/show_source.rb
pry-0.10.0-x64-mingw32 lib/pry/commands/show_source.rb
pry-0.10.0-java lib/pry/commands/show_source.rb
pry-0.10.0.rc1 lib/pry/commands/show_source.rb
pry-0.10.0.rc1-i386-mswin32 lib/pry/commands/show_source.rb
pry-0.10.0.rc1-i386-mingw32 lib/pry/commands/show_source.rb
pry-0.10.0.rc1-x64-mingw32 lib/pry/commands/show_source.rb
pry-0.10.0.rc1-java lib/pry/commands/show_source.rb
pry-0.10.0.pre4 lib/pry/commands/show_source.rb
pry-0.10.0.pre4-i386-mswin32 lib/pry/commands/show_source.rb
pry-0.10.0.pre4-i386-mingw32 lib/pry/commands/show_source.rb
pry-0.10.0.pre4-x64-mingw32 lib/pry/commands/show_source.rb
pry-0.10.0.pre4-java lib/pry/commands/show_source.rb
pry-0.10.0.pre3 lib/pry/commands/show_source.rb
pry-0.10.0.pre3-i386-mswin32 lib/pry/commands/show_source.rb
pry-0.10.0.pre3-i386-mingw32 lib/pry/commands/show_source.rb