June 2007
Intermediate to advanced
294 pages
8h 6m
English
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.
#!/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 ...Read now
Unlock full access