Skip to content

Instantly share code, notes, and snippets.

@exts
Last active January 5, 2017 04:57
Show Gist options
  • Save exts/59a39e8b2d7d86bb3a49af97a4d03ae1 to your computer and use it in GitHub Desktop.
Save exts/59a39e8b2d7d86bb3a49af97a4d03ae1 to your computer and use it in GitHub Desktop.
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