Skip to content
Browse files

Can now view documentation for REPL methods

  • Loading branch information...
1 parent 77387b3 commit 25bba20a95022beefbeab3fe52c591daed4c3f57 @banister banister committed
Showing with 23 additions and 1 deletion.
  1. +23 −1 lib/pry/method.rb
View
24 lib/pry/method.rb
@@ -14,6 +14,8 @@ def Method(obj)
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 @@ def doc
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 @@ def pry_doc_info
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)

0 comments on commit 25bba20

Please sign in to comment.
Something went wrong with that request. Please try again.