1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/show_source.rb
2013-01-12 22:29:32 +01:00

37 lines
1.2 KiB
Ruby

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 --super # for superclass of Pry (Object class)
https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
BANNER
# The source for code_object prepared for display.
def content_for(code_object)
raise CommandError, "Cannot locate source!" if !code_object.source
Code.new(code_object.source, start_line_for(code_object)).
with_line_numbers(use_line_numbers?).to_s
end
end
Pry::Commands.add_command(Pry::Command::ShowSource)
Pry::Commands.alias_command 'show-method', 'show-source'
Pry::Commands.alias_command '$', 'show-source'
end