From 81d44b06740a1a7f3ff0415202a65a9e44ed6330 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 21:50:50 +1200 Subject: [PATCH] allow edit-method to edit rbx core methods using the full path; also added path_line_for helper to wrap source_location and so support rbx core methods too --- lib/pry/default_commands/introspection.rb | 7 ++++++- lib/pry/helpers/command_helpers.rb | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 42147ea4..14fc51fd 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -136,7 +136,12 @@ class Pry # editor is invoked here else - file, line = meth.source_location + if rbx_core?(meth) + file, line = rbx_core_path_line_for(meth) + else + file, line = meth.source_location + end + set_file_and_dir_locals(file) if Pry.editor.respond_to?(:call) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 4a7cd107..990eb610 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -129,7 +129,7 @@ class Pry code = strip_leading_whitespace(meth.source) end end - set_file_and_dir_locals(meth.source_location.first) + set_file_and_dir_locals(path_line_for(meth).first) end [code, code_type] @@ -147,7 +147,7 @@ class Pry else doc = strip_leading_hash_and_whitespace_from_ruby_comments(meth.comment) end - set_file_and_dir_locals(meth.source_location.first) + set_file_and_dir_locals(path_line_for(meth).first) end [doc, code_type] @@ -187,11 +187,19 @@ class Pry end end + def path_line_for(meth) + if rbx_core?(meth) + rbx_core_path_line_for(meth) + else + meth.source_location + end + end + def make_header(meth, code_type, content) num_lines = "Number of lines: #{Pry::Helpers::Text.bold(content.each_line.count.to_s)}" case code_type when :ruby - file, line = meth.source_location + file, line = path_line_for(meth) "\n#{Pry::Helpers::Text.bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n" else file = Pry::MethodInfo.info_for(meth).file