Last active
January 5, 2017 04:57
-
-
Save exts/59a39e8b2d7d86bb3a49af97a4d03ae1 to your computer and use it in GitHub Desktop.
Pass closure blocks to methods/functions as parameter arguments in crystal language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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