Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper
Defined in:
lib/right_agent/tracer.rb,
lib/right_agent/monkey_patches/ruby_patch/object_patch.rb

Overview

Copyright © 2011 RightScale Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

Evaluate the block with the given arguments within the context of this object, so self is set to the method receiver.

From Mauricio’s eigenclass.org/hiki/bounded+space+instance_exec



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/right_agent/monkey_patches/ruby_patch/object_patch.rb', line 32

def instance_exec(*args, &block)
  begin
    old_critical, Thread.critical = Thread.critical, true
    n = 0
    n += 1 while respond_to?(method_name = "__instance_exec#{n}")
    InstanceExecMethods.module_eval { define_method(method_name, &block) }
  ensure
    Thread.critical = old_critical
  end

  begin
    send(method_name, *args)
  ensure
    InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
  end
end

#metaclassObject



25
26
27
28
29
# File 'lib/right_agent/tracer.rb', line 25

def metaclass
  class << self
    self
  end
end