Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Created November 22, 2013 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatrubylove/7604891 to your computer and use it in GitHub Desktop.
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
# 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