Class: Module

Inherits:
Object show all
Defined in:
lib/mixico.rb,
lib/mixico.rb

Instance Method Summary collapse

Instance Method Details

#mix_eval(mod, *args, &blk) ⇒ Object Also known as: mix_exec



118
119
120
121
122
123
124
125
# File 'lib/mixico.rb', line 118

def mix_eval mod, *args, &blk
  blk.mixin mod
  begin
    yield *args
  ensure
    blk.mixout mod
  end
end

#safe_mix_eval(mod, &blk) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/mixico.rb', line 127

def safe_mix_eval mod, &blk
  duped_context = blk.context.dup
  # make sure the singleton class is in existence
  class << duped_context; self; end

  duped_context.redirect_tbls(blk.context)

  duped_context.extend mod
  begin
    m = duped_context.is_a?(Module) ? :class_eval : :instance_eval
    duped_context.send(m, &blk)
  ensure
    duped_context.restore_tbls
    (class << duped_context; self; end).disable_mixin mod
  end
end