Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method proc with parameters

Tags:

crystal-lang

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 Answers

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.

like image 193
Vitalii Elenhaupt Avatar answered Jan 26 '26 01:01

Vitalii Elenhaupt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!