mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
DRYing up show-source/show-doc
This commit is contained in:
parent
fa19e73d93
commit
5fbb3076f1
1 changed files with 11 additions and 29 deletions
|
@ -18,6 +18,17 @@ class Pry
|
|||
rescue CommandError
|
||||
false
|
||||
end
|
||||
|
||||
def process(name)
|
||||
if module?(name)
|
||||
code_or_doc = process_module(name)
|
||||
else method?
|
||||
code_or_doc = process_method
|
||||
end
|
||||
|
||||
render_output(code_or_doc, opts)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Introspection = Pry::CommandSet.new do
|
||||
|
@ -39,17 +50,6 @@ class Pry
|
|||
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
||||
end
|
||||
|
||||
def process(name)
|
||||
|
||||
if module?(name)
|
||||
doc = process_module(name)
|
||||
else method?
|
||||
doc = process_method
|
||||
end
|
||||
|
||||
render_output(doc, opts)
|
||||
end
|
||||
|
||||
def process_module(name)
|
||||
klass = target.eval(name)
|
||||
|
||||
|
@ -91,14 +91,6 @@ class Pry
|
|||
doc
|
||||
end
|
||||
|
||||
# FIXME: stolen from Pry::Method
|
||||
def strip_leading_hash_and_whitespace_from_ruby_comments(comment)
|
||||
comment = comment.dup
|
||||
comment.gsub!(/\A\#+?$/, '')
|
||||
comment.gsub!(/^\s*#/, '')
|
||||
Pry::Helpers::CommandHelpers.unindent(comment)
|
||||
end
|
||||
|
||||
def start_line
|
||||
if opts.present?(:'base-one')
|
||||
1
|
||||
|
@ -167,16 +159,6 @@ class Pry
|
|||
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
||||
end
|
||||
|
||||
def process(name)
|
||||
if module?(name)
|
||||
code = process_module(name)
|
||||
else method?
|
||||
code = process_method
|
||||
end
|
||||
|
||||
render_output(code, opts)
|
||||
end
|
||||
|
||||
def process_method
|
||||
raise CommandError, "Could not find method source" unless method_object.source
|
||||
|
||||
|
|
Loading…
Reference in a new issue