Class: Mixit
- Inherits:
-
Object
- Object
- Mixit
- Defined in:
- lib/mixit.rb,
lib/mixit/version.rb
Constant Summary collapse
- VERSION =
'0.5.2'
Instance Attribute Summary collapse
-
#modules ⇒ Array<Module>
readonly
A list of modules to extend a scope with.
-
#scope ⇒ Object
readonly
The scope to extend.
Instance Method Summary collapse
-
#initialize(opts) {|_self| ... } ⇒ Mixit
constructor
A new instance of Mixit.
-
#temporarily(&block) {|object| ... } ⇒ Object
Temporarily extends scope with methods from module(s).
Constructor Details
#initialize(opts) {|_self| ... } ⇒ Mixit
Returns a new instance of Mixit.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mixit.rb', line 29 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 if block_given? yield(self) end end |
Instance Attribute Details
#modules ⇒ Array<Module> (readonly)
Returns A list of modules to extend a scope with.
9 10 11 |
# File 'lib/mixit.rb', line 9 def modules @modules end |
#scope ⇒ Object (readonly)
Returns The scope to extend.
15 16 17 |
# File 'lib/mixit.rb', line 15 def scope @scope end |
Instance Method Details
#temporarily(&block) {|object| ... } ⇒ Object
Temporarily extends scope with methods from module(s).
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mixit.rb', line 59 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 |