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

lb563 · April 17, 2012 · Last by doitian replied at April 17, 2012 · 2266 hits

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

# 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*)
}

You need to Sign in before reply, if you don't have an account, please Sign up first.