Ruby 怎么向传过来的 block 中添加一些 block

lb563 · 2012年04月17日 · 最后由 doitian 回复于 2012年04月17日 · 2264 次阅读

可能有点绕,是这样的: 如下代码:

# Registers a brand new configuration for the given resource.
   def register(resource, options = {}, &block)
     namespace_name = extract_namespace_name(options)
     namespace = find_or_create_namespace(namespace_name)
     namespace.register(resource, options, &block)
   end

我需要重写这个方法,但是我需要在传过来的&block 中添加一些方法再传给其它方法 例如:方法" namespace.register(resource, options, &block) " 我应该怎么把&block 打开然后向里面加我想要的 block

new_block =  Proc.new { block.call }
namespace.register(resource.options, &new_block)


namespace.register(resource, options) { |args*|
  # 该干嘛干嘛
  block.call(args*)
}

需要 登录 后方可回复, 如果你还没有账号请 注册新账号