不确定但是在 ruby 中你可以使用&as-patterns
来实现类似的东西lambda
proc
对于第一种模式
2.3.1 :030 > pattern = Proc.new {|x, y, z| x + (y * z) }
=> #<Proc:0x007fa6fd5a2188@(irb):30>
2.3.1 :031 > func = lambda { |arr| arr.map {|ar| pattern.call(*ar)} }
=> #<Proc:0x007fa6fddc1328@(irb):31 (lambda)>
2.3.1 :032 > func.call([[1,2,3], [4,5,6]])
=> [7, 34]
对于第二个模式
2.3.1 :033 > pattern = Proc.new {|x, y, z| [x + (y * z), [y, z]] }
=> #<Proc:0x007fa6ffba5150@(irb):33>
2.3.1 :034 > func = lambda { |arr| arr.map {|ar| pattern.call(*ar)} }
=> #<Proc:0x007fa6fdd60aa0@(irb):34 (lambda)>
2.3.1 :035 > func.call([[1,2,3], [4,5,6]])
=> [[7, [2, 3]], [34, [5, 6]]]