lib/missile_emitter.rb in missile_emitter-0.2.0 vs lib/missile_emitter.rb in missile_emitter-0.3.0
- old
+ new
@@ -16,11 +16,11 @@
attr_accessor :mapping
def exec(namespace, &block)
raise Error.new("需要提供代码块") unless block_given?
- context = block.binding.eval 'self'
+ context = block.binding.receiver
raise Error.new("只能再具名模块中调用") unless context.instance_of?(Module) && context.name
mimic_method context, namespace: namespace
@@ -37,14 +37,14 @@
# 处理嵌套模块
container = !ns.empty? && namespace ? constantize(ns) : Kernel
action = container == Kernel ? 'define_method' : 'define_singleton_method'
- container.send action, name do |&missile|
- klass = missile.binding.eval 'self'
+ container.send action, name do |*args, &missile|
+ klass = missile.binding.receiver
battle_field = BattleField.new klass, MissileEmitter.mapping[context]
- battle_field.emit! &missile
+ battle_field.emit! *args, &missile
context
end
end
@@ -85,9 +85,10 @@
constant.const_get(name, false)
end
end
end
+
end
end
module Kernel