呼叫阻止呼叫不起作用

Call block with call not work

我尝试使用此 issue

中的代码
def call(&block)
  block.call(3, "test")
end

call do |x, y|
  puts x
  {x, y}
end

但只得到错误:

wrong number of block arguments (given 2, expected 0)

可以吗,也许还有其他调用块的方法?

游乐场link:https://play.crystal-lang.org/#/r/4t8h

Github 问题:https://github.com/crystal-lang/crystal/issues/6597

您可以使用以下两种形式之一:

def call(&block : Int32, String -> {Int32, String})
  block.call(3, "test")
end

result = call do |x, y|
  {x, y}
end

result # => {3, "test"}

def call
  yield 3, "test"
end

result = call do |x, y|
  {x, y}
end

result # => {3, "test"}

还可以找到一些额外的信息here.