lib/rubyrun/rubyrun_instrumentor__.rb in rubyrun-0.9.6 vs lib/rubyrun/rubyrun_instrumentor__.rb in rubyrun-0.9.7

- old
+ new

@@ -137,35 +137,37 @@ # 4. This proxy method essentially adds pre and post wrapper code to # the original code. This wrapper code is embodied in collect_method_data # 5. All these must be done in the context of the class def insert_code_to_instance_method(klass, mid) klass.class_eval { - alias_method "#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}", mid.id2name - eval <<-CODE1 + alias_name = "#{RubyRunGlobals::RUBYRUN_PREFIX}_#{rand.to_s.split('.')[1]}_#{mid.id2name}" + alias_method alias_name, mid.id2name + eval <<-BODY1 def #{mid.id2name} (*args, &blk) - RubyRunInstrumentor__.collect_method_data(self, #{klass}, '#{mid}', *args) {self.send("#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}", *args, &blk)} + RubyRunInstrumentor__.collect_method_data(self, #{klass}, '#{mid}', *args) {self.send("#{alias_name}", *args, &blk)} end - CODE1 - if klass.private_instance_methods(false).include?("#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}") + BODY1 + if klass.private_instance_methods(false).include?(alias_name) private mid - elsif klass.protected_instance_methods(false).include?("#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}") + elsif klass.protected_instance_methods(false).include?(alias_name) protected mid end } end # Same as insert_code_to_instance_method def insert_code_to_singleton_method(klass, mid) (class << klass; self; end).class_eval { - alias_method "#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}", mid.id2name - eval <<-EOF2 + alias_name = "#{RubyRunGlobals::RUBYRUN_PREFIX}_#{rand.to_s.split('.')[1]}_#{mid.id2name}" + alias_method alias_name, mid.id2name + eval <<-BODY2 def #{mid.id2name} (*args, &blk) - RubyRunInstrumentor__.collect_method_data(self, #{klass}, '#{mid}', *args) {self.send("#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}", *args, &blk)} + RubyRunInstrumentor__.collect_method_data(self, #{klass}, '#{mid}', *args) {self.send("#{alias_name}", *args, &blk)} end - EOF2 - if self.private_instance_methods(false).include?("#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}") + BODY2 + if self.private_instance_methods(false).include?(alias_name) private mid - elsif self.protected_instance_methods(false).include?("#{RubyRunGlobals::RUBYRUN_PREFIX}_#{mid.id2name}") + elsif self.protected_instance_methods(false).include?(alias_name) protected mid end } end \ No newline at end of file