From 74d3d0da489313f73e0883ee3c15521b96b63f9c Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 13 Apr 2012 18:36:24 +1200 Subject: [PATCH] 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 --- lib/pry/method.rb | 17 +++++++++++++---- lib/pry/rbx_method.rb | 11 ++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 8fce427d..3cd4150d 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -250,8 +250,8 @@ class Pry 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 @@ class Pry 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 @@ class Pry 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 diff --git a/lib/pry/rbx_method.rb b/lib/pry/rbx_method.rb index 3e9243cc..b5a64fbe 100644 --- a/lib/pry/rbx_method.rb +++ b/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