1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Can now view documentation for REPL methods

This commit is contained in:
John Mair 2012-04-17 23:26:45 +12:00
parent 77387b3e5c
commit 25bba20a95

View file

@ -14,6 +14,8 @@ class Pry
end
end
# This class wraps the normal `Method` and `UnboundMethod` classes
# to provide extra functionality useful to Pry.
class Method
include RbxMethod if Helpers::BaseHelpers.rbx?
include Helpers::DocumentationHelpers
@ -274,7 +276,9 @@ class Pry
if Helpers::BaseHelpers.rbx? && !pry_method?
strip_leading_hash_and_whitespace_from_ruby_comments(core_doc)
elsif pry_method?
raise CommandError, "Can't view doc for a REPL-defined method."
# raise CommandError, "Can't view doc for a REPL-defined
# method."
strip_leading_hash_and_whitespace_from_ruby_comments(doc_for_pry_method)
else
strip_leading_hash_and_whitespace_from_ruby_comments(@method.comment)
end
@ -432,6 +436,24 @@ class Pry
end
end
# FIXME: a very similar method to this exists on WrappedModule: extract_doc_for_candidate
def doc_for_pry_method
_, line = source_location
buffer = ""
Pry.line_buffer[0..(line - 1)].each do |line|
# Add any line that is a valid ruby comment,
# but clear as soon as we hit a non comment line.
if (line =~ /^\s*#/) || (line =~ /^\s*$/)
buffer << line.lstrip
else
buffer.replace("")
end
end
buffer
end
# @param [Class,Module] the ancestors to investigate
# @return [Method] the unwrapped super-method
def super_using_ancestors(ancestors, times=1)