Class: Object
Defined Under Namespace
Modules: InstanceExecMethods
Instance Method Summary collapse
-
#extend_with_included_modules_from(object) ⇒ Object
:nodoc:.
-
#extended_by ⇒ Object
:nodoc:.
-
#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.
-
#remove_subclasses_of(*superclasses) ⇒ Object
:nodoc:.
Instance Method Details
#extend_with_included_modules_from(object) ⇒ Object
:nodoc:
50 51 52 |
# File 'lib/ircbot/core_ext/extending.rb', line 50 def extend_with_included_modules_from(object) #:nodoc: object.extended_by.each { |mod| extend mod } end |
#extended_by ⇒ Object
:nodoc:
45 46 47 48 |
# File 'lib/ircbot/core_ext/extending.rb', line 45 def extended_by #:nodoc: ancestors = class << self; ancestors end ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] end |
#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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ircbot/core_ext/extending.rb', line 63 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 |
#remove_subclasses_of(*superclasses) ⇒ Object
:nodoc:
2 3 4 |
# File 'lib/ircbot/core_ext/extending.rb', line 2 def remove_subclasses_of(*superclasses) #:nodoc: Class.remove_class(*subclasses_of(*superclasses)) end |