Method proc with parameters
Asked Answered
M

1

3

Is possible to use method proc with parameters in Crystal ?

Something like:

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

proc = ->foo

proc.call "Hi"
Murrhine answered 13/10, 2017 at 11:12 Comment(0)
Q
2

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.

Quillon answered 13/10, 2017 at 11:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.