2013-01-01 21:25:23 +01:00
|
|
|
require 'pry/commands/show_info'
|
2012-08-11 17:22:29 -07:00
|
|
|
|
2013-01-01 21:25:23 +01:00
|
|
|
class Pry
|
|
|
|
class Command::ShowSource < Command::ShowInfo
|
2012-12-25 23:35:17 +02:00
|
|
|
match 'show-source'
|
2012-08-11 18:26:59 -07:00
|
|
|
group 'Introspection'
|
2013-01-09 22:23:19 +02:00
|
|
|
description 'Show the source for a method or class.'
|
2012-08-11 17:22:29 -07:00
|
|
|
|
2013-01-09 22:23:19 +02:00
|
|
|
banner <<-'BANNER'
|
|
|
|
Usage: show-source [OPTIONS] [METH|CLASS]
|
2012-08-11 17:22:29 -07:00
|
|
|
Aliases: $, show-method
|
|
|
|
|
2013-01-09 22:23:19 +02:00
|
|
|
Show the source for a method or class. Tries instance methods first and then
|
|
|
|
methods by default.
|
2012-08-11 17:22:29 -07:00
|
|
|
|
2013-01-09 22:23:19 +02:00
|
|
|
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 --super # for superclass of Pry (Object class)
|
2012-08-11 17:22:29 -07:00
|
|
|
|
|
|
|
https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
|
|
|
|
BANNER
|
|
|
|
|
2013-01-01 22:45:23 +01:00
|
|
|
# The source for code_object prepared for display.
|
|
|
|
def content_for(code_object)
|
2013-01-12 22:15:25 +01:00
|
|
|
raise CommandError, "Cannot locate source!" if !code_object.source
|
2013-01-01 22:45:23 +01:00
|
|
|
Code.new(code_object.source, start_line_for(code_object)).
|
2012-12-25 13:47:33 +01:00
|
|
|
with_line_numbers(use_line_numbers?).to_s
|
|
|
|
end
|
2012-08-11 17:22:29 -07:00
|
|
|
end
|
|
|
|
|
2012-12-25 23:35:17 +02:00
|
|
|
Pry::Commands.add_command(Pry::Command::ShowSource)
|
|
|
|
Pry::Commands.alias_command 'show-method', 'show-source'
|
|
|
|
Pry::Commands.alias_command '$', 'show-source'
|
2012-08-11 17:22:29 -07:00
|
|
|
end
|