Module: RConditions
- Defined in:
- lib/rconditions.rb
Overview
Holds RCondition’s methods. You should never call these methods directly, as they are automatically called.
Class Method Summary collapse
-
.add_exception_module(mod) ⇒ Object
:nodoc:.
-
.collect_exception_modules ⇒ Object
:nodoc:.
-
.extend_predicate_method_and_define_bang_method(mod, id) ⇒ Object
Extends a given predicate method and defines a bang method for it.
-
.extend_predicate_methods_and_define_bang_methods ⇒ Object
Extends almost all predicate methods and defines bang methods for them.
Class Method Details
.add_exception_module(mod) ⇒ Object
:nodoc:
48 49 50 51 52 |
# File 'lib/rconditions.rb', line 48 def add_exception_module(mod) #:nodoc: if mods = Thread.current[:rconditions_exception_modules] mods << mod end end |
.collect_exception_modules ⇒ Object
:nodoc:
40 41 42 43 44 45 46 |
# File 'lib/rconditions.rb', line 40 def collect_exception_modules #:nodoc: mods = Thread.current[:rconditions_exception_modules] = [] yield mods ensure Thread.current[:rconditions_exception_modules] = nil end |
.extend_predicate_method_and_define_bang_method(mod, id) ⇒ Object
Extends a given predicate method and defines a bang method for it. You should never call this method yourself, it is called either from RConditions#extend_predicate_methods_and_define_bang_methods, or from Module#method_added or Object#singleton_method_added which are extended by RConditions.
-
mod– the module on which the method is defined. -
id– the name of the method.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rconditions.rb', line 13 def extend_predicate_method_and_define_bang_method(mod, id) return if Thread.current[:rconditions_processing_predicate_method] return if (predicate_method = id.to_s) !~ PREDICATE_METHOD return if mod == Kernel && predicate_method == 'block_given?' begin Thread.current[:rconditions_processing_predicate_method] = true extend_predicate_method(mod, predicate_method) define_bang_method(mod, predicate_method) ensure Thread.current[:rconditions_processing_predicate_method] = false end end |
.extend_predicate_methods_and_define_bang_methods ⇒ Object
Extends almost all predicate methods and defines bang methods for them. You should never call this method yourself, it is called automatically when RConditions is required. To prevent it from being called, set ::RCONDITIONS_ONLY_FOR_NEW_METHODS to true before requiring RConditions.
32 33 34 35 36 37 38 |
# File 'lib/rconditions.rb', line 32 def extend_predicate_methods_and_define_bang_methods ObjectSpace.each_object(Module) do |mod| (mod.instance_methods(false) + mod.private_instance_methods(false)).each do |id| ::RConditions.extend_predicate_method_and_define_bang_method(mod, id) end end end |