Skip to content
Browse files

define a Pry::Method#source_location, fixes #524

* This fixes _file_ for rbx core methods by special casing rbx right at Pry::Method#source_location, as a result
most things down stream should 'just work' with rbx, with no other checks required
  • Loading branch information...
1 parent fa6791e commit 74d3d0da489313f73e0883ee3c15521b96b63f9c @banister banister committed Apr 13, 2012
Showing with 15 additions and 13 deletions.
  1. +13 −4 lib/pry/method.rb
  2. +2 −9 lib/pry/rbx_method.rb
View
17 lib/pry/method.rb
@@ -250,8 +250,8 @@ def source
code = strip_comments_from_c_code(info.source)
end
when :ruby
- if Helpers::BaseHelpers.rbx? && core?
- code = core_code
+ if Helpers::BaseHelpers.rbx? && !pry_method?
+ code = core_code
elsif pry_method?
code = Pry.new(:input => StringIO.new(Pry.line_buffer[source_line..-1].join), :prompt => proc {""}, :hooks => Pry::Hooks.new).r
else
@@ -270,8 +270,8 @@ def doc
info = pry_doc_info
info.docstring if info
when :ruby
- if Helpers::BaseHelpers.rbx? && core?
- strip_leading_hash_and_whitespace_from_ruby_comments(core_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."
else
@@ -286,6 +286,15 @@ def source_type
source_location.nil? ? :c : :ruby
end
+ def source_location
+ if Helpers::BaseHelpers.rbx?
+ file, line = @method.source_location
+ [RbxPath.convert_path_to_full(file), line]
+ else
+ @method.source_location
+ end
+ end
+
# @return [String, nil] The name of the file the method is defined in, or
# `nil` if the filename is unavailable.
def source_file
View
11 lib/pry/rbx_method.rb
@@ -1,20 +1,13 @@
class Pry
module RbxMethod
private
- def core?
- source_file and RbxPath.is_core_path?(source_file)
- end
def core_code
- MethodSource.source_helper(core_path_line)
+ MethodSource.source_helper(source_location)
end
def core_doc
- MethodSource.comment_helper(core_path_line)
- end
-
- def core_path_line
- [RbxPath.convert_path_to_full(source_file), source_line]
+ MethodSource.comment_helper(source_location)
end
end
end

0 comments on commit 74d3d0d

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