Module: Rack::Mount::Mixover
- Included in:
- Analysis::Frequency, Route, RouteSet
- Defined in:
- lib/rack/mount/mixover.rb
Overview
A mixin that changes the behavior of include
. Instead of modules being chained as a superclass, they are mixed into the objects metaclass. This allows mixins to be stacked ontop of the instance methods.
Defined Under Namespace
Modules: InstanceMethods
Instance Method Summary collapse
-
#include(*mod) ⇒ Object
Replaces include with a lazy version.
-
#new(*args, &block) ⇒ Object
:nodoc:.
-
#new_with_module(mod, *args, &block) ⇒ Object
Create a new class temporarily with a module.
-
#new_without_module(mod, *args, &block) ⇒ Object
Create a new class without an included module.
Instance Method Details
#include(*mod) ⇒ Object
Replaces include with a lazy version.
17 18 19 |
# File 'lib/rack/mount/mixover.rb', line 17 def include(*mod) (@included_modules ||= []).push(*mod) end |
#new(*args, &block) ⇒ Object
:nodoc:
21 22 23 24 25 26 27 |
# File 'lib/rack/mount/mixover.rb', line 21 def new(*args, &block) #:nodoc: obj = allocate obj.extend(InstanceMethods) (@included_modules ||= []).each { |mod| obj.extend(mod) } obj.send(:initialize, *args, &block) obj end |
#new_with_module(mod, *args, &block) ⇒ Object
Create a new class temporarily with a module.
39 40 41 42 43 44 45 |
# File 'lib/rack/mount/mixover.rb', line 39 def new_with_module(mod, *args, &block) old_included_modules = (@included_modules ||= []).dup include(mod) new(*args, &block) ensure @included_modules = old_included_modules end |
#new_without_module(mod, *args, &block) ⇒ Object
Create a new class without an included module.
30 31 32 33 34 35 36 |
# File 'lib/rack/mount/mixover.rb', line 30 def new_without_module(mod, *args, &block) old_included_modules = (@included_modules ||= []).dup @included_modules.delete(mod) new(*args, &block) ensure @included_modules = old_included_modules end |