Created
November 22, 2013 18:47
-
-
Save thatrubylove/7604891 to your computer and use it in GitHub Desktop.
lambda example for 2013-11-20-welcome-to-ruby-love-a-blog-where-we-love-ruby
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
# Functional coding in Ruby - better than chunky bacon | |
print_to_console = ->(msg) { puts msg } | |
print_to_motd_file = ->(msg) { File.write("motd.txt", msg) } | |
# Display the "message of the day" via the selected printer | |
motd = ->(printer) { | |
msg = ["Hello World,\n", | |
" Sincerely,\n", | |
" thatrubylove"].join | |
printer.(msg) | |
} | |
# Echo to the console | |
motd.(print_to_console) | |
# write to a file | |
motd.(print_to_motd_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment