Class: Mixit
- Inherits:
-
Object
- Object
- Mixit
- Defined in:
- lib/mixit.rb,
lib/mixit/version.rb
Constant Summary collapse
- VERSION =
'0.5.1'
Instance Attribute Summary collapse
-
#modules ⇒ Array<Module>
readonly
An Array of modules to extend a scope with.
-
#scope ⇒ Object
readonly
The scope to extend.
Class Method Summary collapse
-
.temporarily(opts, &block) {|object| ... } ⇒ Object
Temporarily extends a scope with instance methods from module(s).
Instance Method Summary collapse
-
#initialize(opts) ⇒ Mixit
constructor
A new instance of Mixit.
-
#temporarily(&block) {|object| ... } ⇒ Object
Temporarily extends scope with methods from module(s).
Constructor Details
#initialize(opts) ⇒ Mixit
Returns a new instance of Mixit.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mixit.rb', line 52 def initialize opts @clones = [] @modules = opts[:modules] case opts[:scope] when Binding @scope = opts[:scope].eval "self" when Proc @scope = opts[:scope].binding.eval "self" else @scope = opts[:scope] end end |
Instance Attribute Details
#modules ⇒ Array<Module> (readonly)
Returns An Array of modules to extend a scope with.
34 35 36 |
# File 'lib/mixit.rb', line 34 def modules @modules end |
#scope ⇒ Object (readonly)
Returns The scope to extend.
40 41 42 |
# File 'lib/mixit.rb', line 40 def scope @scope end |
Class Method Details
.temporarily(opts, &block) {|object| ... } ⇒ Object
Temporarily extends a scope with instance methods from module(s).
24 25 26 27 |
# File 'lib/mixit.rb', line 24 def temporarily opts, &block mixit = new(opts) mixit.temporarily(&block) end |
Instance Method Details
#temporarily(&block) {|object| ... } ⇒ Object
Temporarily extends scope with methods from module(s).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/mixit.rb', line 78 def temporarily &block if block.arity == 1 value = block.call extend_scope!(:clone => true) else begin value = extend_scope!(:clone => false).instance_eval(&block) ensure remove_methods! trigger_callback! end end value end |