Skip to content

Eliminate usage of ObjectSpace._id2ref #63

Merged
merged 1 commit into from Jun 25, 2011
View
15 lib/rr/injections/double_injection.rb
@@ -119,11 +119,15 @@ def bind
self
end
+ BoundObjects = {}
+
def bind_method_that_self_destructs_and_delegates_to_method_missing
- subject_class_object_id = subject_class.object_id
+ id = BoundObjects.size
+ BoundObjects[id] = subject_class
+
subject_class.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def #{method_name}(*args, &block)
- ObjectSpace._id2ref(#{subject_class_object_id}).class_eval do
+ ::RR::Injections::DoubleInjection::BoundObjects[#{id}].class_eval do
remove_method(:#{method_name})
end
method_missing(:#{method_name}, *args, &block)
@@ -133,11 +137,14 @@ def #{method_name}(*args, &block)
end
def bind_method
- subject_class_object_id = subject_class.object_id
+ id = BoundObjects.size
+ BoundObjects[id] = subject_class
+
subject_class.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def #{method_name}(*args, &block)
arguments = MethodArguments.new(args, block)
- RR::Injections::DoubleInjection.dispatch_method(self, ObjectSpace._id2ref(#{subject_class_object_id}), :#{method_name}, arguments.arguments, arguments.block)
+ obj = ::RR::Injections::DoubleInjection::BoundObjects[#{id}]
+ RR::Injections::DoubleInjection.dispatch_method(self, obj, :#{method_name}, arguments.arguments, arguments.block)
end
RUBY
self
View
9 lib/rr/injections/method_missing_injection.rb
@@ -51,11 +51,16 @@ def reset
end
protected
+ BoundObjects = {}
+
def bind_method
- subject_class_object_id = subject_class.object_id
+ id = BoundObjects.size
+ BoundObjects[id] = subject_class
+
subject_class.class_eval((<<-METHOD), __FILE__, __LINE__ + 1)
def method_missing(method_name, *args, &block)
- MethodDispatches::MethodMissingDispatch.new(self, ObjectSpace._id2ref(#{subject_class_object_id}), method_name, args, block).call
+ obj = ::RR::Injections::MethodMissingInjection::BoundObjects[#{id}]
+ MethodDispatches::MethodMissingDispatch.new(self, obj, method_name, args, block).call
end
METHOD
end
Something went wrong with that request. Please try again.