Generating a list of countries in Ruby
Making use of the tzinfo gem (gem install tzinfo) in Ruby makes it easy to list, iterate over and display the countries of the world.
For extra usefulness, the library includes the associated ISO 3166 two letter code each country, which makes it easier when sending them around a web application.
You can make use of it with the following...
require 'tzinfo'
# Get one country
us = TZInfo::Country.get('US')
# Get all countries
all = TZInfo::Country.all
# Get all codes
codes = TZInfo::Country.all_codes
# One liner to dump out all codes and their associated country name
TZInfo::Country.all_codes.map { |code| puts "#{code} : #{TZInfo::Country.get(code).name}"
There may be a more efficient way to do the latter, but as the blog title suggests, it is a quick and dirty Code Fudge.