lib/egi/sandbox.rb in egi-0.0.2 vs lib/egi/sandbox.rb in egi-0.0.3
- old
+ new
@@ -11,26 +11,33 @@
def env(name, opts = {}, &block)
name = name.to_sym
@current_env = name
to_load = opts[:load]
- env = envs[name]
- env.merge!(envs[to_load]) if envs.has_key?(to_load)
- env.instance_eval(&block) if block_given?
-
- # define method_missing to access item
- def env.method_missing(name, *args)
- raise MethodMissing if args.size > 0
- items.has_key?(name) ? items[name] : nil
- end
+ envs[name].merge!(envs[to_load]) if envs.has_key?(to_load)
+ envs[name].instance_eval(&block) if block_given?
end
def eval(str)
instance_eval(str)
+
+ # define method_missing to access items
+ envs.each_value do |env|
+ def env.method_missing(name, *args)
+ super if args.size > 0
+ items.has_key?(name) ? items[name] : nil
+ end
+ end
+
envs
end
- def method_missing(name, *args)
- envs[@current_env].send(name, *args)
+ def method_missing(name, *args, &block)
+ begin
+ envs[@current_env].send(name, *args, &block)
+ rescue => e
+ puts "#{name}(#{args}) #{block_given? ? "with block" : ""} is called at #{@current_env} env"
+ raise e
+ end
end
end
end