Method proc with parameters

我只是一个虾纸丫 提交于 2019-12-12 15:37:39

问题


Is possible to use method proc with parameters in Crystal ?

Something like:

def foo(baz)
  puts "#{baz} foo!"
end

proc = ->foo

proc.call "Hi"

回答1:


Yes. If the method has arguments, you must specify their types:

proc = ->foo(String)
proc.call "Hi" # Hi foo!

Find more examples at crystal docs.



来源:https://stackoverflow.com/questions/46728581/method-proc-with-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!