Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate usage of ObjectSpace._id2ref #63

Merged
merged 1 commit into from Jun 25, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/rr/injections/double_injection.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/rr/injections/method_missing_injection.rb
Expand Up @@ -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
Expand Down