Skip to content

Instantly share code, notes, and snippets.

@exts
Last active January 5, 2017 04:57
Embed
What would you like to do?
Pass closure blocks to methods/functions as parameter arguments in crystal language
# idiotcoder.com
def example(&ex)
ex.call()
end
example &-> {
puts "sup"
}
example do
puts "hey 2"
end
def example2(&ex2 : String ->)
ex2.call("You'll have access to this string inside your closure")
end
example2 do |str|
puts str
puts "called after the str"
end
example2 &->(str : String) {
puts str
puts "hello"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment