diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2013-03-28 00:24:12 -0700 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2013-03-28 00:25:50 -0700 |
commit | da1283b0009ee052c41a3b3b2659949dff794b7b (patch) | |
tree | 3ddb5fa1213d9ea2b1b3a21c9f783ef86ea532e9 | |
parent | e43daac85c521e39ca86abde0f9dc8e44f5abcd9 (diff) | |
download | pry-da1283b0009ee052c41a3b3b2659949dff794b7b.tar.gz |
s/code_object/method
-rw-r--r-- | lib/pry/method/patcher.rb | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/pry/method/patcher.rb b/lib/pry/method/patcher.rb index 47a45e3a..687b46ce 100644 --- a/lib/pry/method/patcher.rb +++ b/lib/pry/method/patcher.rb @@ -1,22 +1,22 @@ class Pry class Method class Patcher - attr_accessor :code_object + attr_accessor :method @@source_cache = {} - def initialize(code_object) - @code_object = code_object + def initialize(method) + @method = method end def cached_source - @@source_cache[code_object.source_file] + @@source_cache[method.source_file] end # perform the patch def perform_patch source = patched_code - if code_object.alias? + if method.alias? with_method_transaction do cached_eval source end @@ -33,11 +33,11 @@ class Pry end def patched_code - @patched_code ||= wrap(Pry::Editor.edit_tempfile_with_content(code_object.source.lines.to_a)) + @patched_code ||= wrap(Pry::Editor.edit_tempfile_with_content(method.source.lines.to_a)) end def cache_key - "pry!#{code_object.owner.object_id}!#{code_object.name}" + "pry!#{method.owner.object_id}!#{method.name}" end # Run some code ensuring that at the end target#meth_name will not have changed. @@ -51,17 +51,17 @@ class Pry # @param [Module] target The owner of the method def with_method_transaction - temp_name = "__pry_#{code_object.original_name}__" - co = code_object - code_object.owner.class_eval do - alias_method temp_name, co.original_name + temp_name = "__pry_#{method.original_name}__" + method = self.method + method.owner.class_eval do + alias_method temp_name, method.original_name yield - alias_method co.name, co.original_name - alias_method co.original_name, temp_name + alias_method method.name, method.original_name + alias_method method.original_name, temp_name end ensure - co.send(:remove_method, temp_name) rescue nil + method.send(:remove_method, temp_name) rescue nil end # Update the definition line so that it can be eval'd directly on the Method's @@ -77,10 +77,10 @@ class Pry # @param String The original definition line. e.g. def self.foo(bar, baz=1) # @return String The new definition line. e.g. def foo(bar, baz=1) def definition_for_owner(line) - if line =~ /\Adef (?:.*?\.)?#{Regexp.escape(code_object.original_name)}(?=[\(\s;]|$)/ - "def #{code_object.original_name}#{$'}" + if line =~ /\Adef (?:.*?\.)?#{Regexp.escape(method.original_name)}(?=[\(\s;]|$)/ + "def #{method.original_name}#{$'}" else - raise CommandError, "Could not find original `def #{code_object.original_name}` line to patch." + raise CommandError, "Could not find original `def #{method.original_name}` line to patch." end end @@ -100,7 +100,7 @@ class Pry # @param [String] source The source to wrap # @return [String] def wrap_for_owner(source) - Pry.current[:pry_owner] = code_object.owner + Pry.current[:pry_owner] = method.owner owner_source = definition_for_owner(source) "Pry.current[:pry_owner].class_eval do\n#{owner_source}\nend" end @@ -118,7 +118,7 @@ class Pry # @param [String] source The source to wrap. # @return [String] def wrap_for_nesting(source) - nesting = Pry::Code.from_file(code_object.source_file).nesting_at(code_object.source_line) + nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line) (nesting + [source] + nesting.map{ "end" } + [""]).join("\n") rescue Pry::Indent::UnparseableNestingError |