From 7454d549e849cbb9c278c58c470f7d6513c58ae3 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 27 Mar 2013 23:48:20 -0700 Subject: [PATCH] Split up big Pry::Method#source method --- lib/pry/method.rb | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 42749fb6..434ccef2 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -264,23 +264,9 @@ class Pry def source @source ||= case source_type when :c - info = pry_doc_info - if info and info.source - code = strip_comments_from_c_code(info.source) - end + c_source when :ruby - # clone of MethodSource.source_helper that knows to use our - # hacked version of source_location for rbx core methods, and - # our input buffer for methods defined in (pry) - file, line = *source_location - raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file - - begin - code = Pry::Code.from_file(file).expression_at(line) - rescue SyntaxError => e - raise MethodSource::SourceNotFoundError.new(e.message) - end - strip_leading_whitespace(code) + ruby_source end end @@ -548,5 +534,27 @@ class Pry nil end + + def c_source + info = pry_doc_info + if info and info.source + strip_comments_from_c_code(info.source) + end + end + + def ruby_source + # clone of MethodSource.source_helper that knows to use our + # hacked version of source_location for rbx core methods, and + # our input buffer for methods defined in (pry) + file, line = *source_location + raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file + + begin + code = Pry::Code.from_file(file).expression_at(line) + rescue SyntaxError => e + raise MethodSource::SourceNotFoundError.new(e.message) + end + strip_leading_whitespace(code) + end end end