#2 Random Signature Generator (random_sig.rb and random_sig-windows.rb)
The next script generates dynamic content for email signatures, adding standard information, like a name and email address, to a random quotation drawn from a known file. The Unix and Windows versions need to be slightly different, so they have been separated into two distinct files. I’ll talk about the Unix version first, but will include the source code for both files. In this example, we’ll also see how Ruby handles complex assignments. That’s a lot of information to cover.
The Code
#!/usr/bin/env ruby
# random_sig.rb
❶ filename = ARGV[0] || (ENV['HOME'] + '/scripts/sig_quotes.txt') Environment Variables; The File Object ❷ quotation_file = File.new(filename, 'r') file_lines ...
Get Ruby by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.