Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.