调用Procs的bizzare方式?

我找到了一个示例代码:

def callback(procs) procs[:var_1] puts "Proceed" procs[:var_2] end callback(:var_1 => Proc.new {block_1}, :var_2 => Proc.new {block_2}) 

我无法弄清楚方括号[:var_1]含义。 这是一种调用Porc / lambda的方法吗? 我也很困惑,因为在类似Hash的方式创建Procs:

 callback(:start => Proc.new {puts "The begining of the CALLBACK"}, :finish => Proc.new {puts "The ending of the CALLBACK"}) 

对此事我感激不尽。

方法回调是构建的,因此它正在接收哈希。 这个哈希存储针对每个键的procs,有时执行你需要使用其键从哈希中获取它的proc:

 hash = { :start => Proc.new {puts "The begining of the CALLBACK"}, :finish => Proc.new {puts "The ending of the CALLBACK"} } hash[:start] #=> proc object you can call `call` on.