diff --git a/lib/pry/code.rb b/lib/pry/code.rb index c8c9c52d1..36cd6c9a3 100644 --- a/lib/pry/code.rb +++ b/lib/pry/code.rb @@ -61,6 +61,8 @@ class << self def from_file(filename, code_type = type_from_filename(filename)) code = if filename == Pry.eval_path Pry.line_buffer.drop(1) + elsif Pry::Method::Patcher.code_for(filename) + Pry::Method::Patcher.code_for(filename) else File.read(abs_path(filename)) end diff --git a/lib/pry/method.rb b/lib/pry/method.rb index acf91e46d..40bcda401 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -266,7 +266,7 @@ def source when :c c_source when :ruby - Patcher.new(self).cached_source || ruby_source + ruby_source end end diff --git a/lib/pry/method/patcher.rb b/lib/pry/method/patcher.rb index 07dfa8fb8..ef09722e9 100644 --- a/lib/pry/method/patcher.rb +++ b/lib/pry/method/patcher.rb @@ -9,8 +9,8 @@ def initialize(method) @method = method end - def cached_source - @@source_cache[method.source_file] + def self.code_for(filename) + @@source_cache[filename] end # perform the patch @@ -97,7 +97,7 @@ def wrap(source) def wrap_for_owner(source) Pry.current[:pry_owner] = method.owner owner_source = definition_for_owner(source) - "Pry.current[:pry_owner].class_eval do\n#{owner_source}\nend" + "Pry.current[:pry_owner].class_eval do; #{owner_source}\nend" end # Update the new source code to have the correct Module.nesting. @@ -115,7 +115,7 @@ def wrap_for_owner(source) def wrap_for_nesting(source) nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line) - (nesting + [source] + nesting.map{ "end" } + [""]).join("\n") + (nesting + [source] + nesting.map{ "end" } + [""]).join(";") rescue Pry::Indent::UnparseableNestingError source end