> Write a Ruby program such that given a certain argument to the program it
> will return the current temperature of that location.  People living in
> the United States may be interested in temperature by ZIP code:

This is my first submission to rubyquiz.  I've been learning ruby for
about 6 months now, and it's my first foray into programming.  I'd love
some feedback.

Thanks,

# current_temp.rb

require 'net/http'
require 'rexml/document'
require 'optparse'

class CurrentTemp
  include REXML

  def initialize(loc,u='f')
    uri = "http://xml.weather.yahoo.com/forecastrss?p=#{loc}&u=#{u}"
    @doc = Document.new Net::HTTP.get(URI.parse(uri))
    raise "Invalid city, #{loc}" if /error/i =~
@doc.elements["//description"].to_s
  end

  def method_missing(methodname)
    XPath.match(@doc,"//*[starts-with(name(), 'yweather')]").each
do|elem|
      return elem.attributes[methodname.to_s] if
elem.attributes[methodname.to_s]
    end
    Object.method_missing(methodname)
  end

  def unit
    self.temperature
  end

  def state
    self.region
  end

  def to_s
    "The current temperature in #{self.city}, #{self.state} is
#{self.temp} degrees #{self.unit}."
  end

end

opts = OptionParser.new
opts.banner = "Usage:\n\n    current_temp.rb city [-u unit]\n\n    "
opts.banner += "city should be a zip code, or a Yahoo Weather location
id.\n\n"
opts.on("-uARG", "--unit ARG","Should be f or c", String) {|val| @u =
val }
opts.on("-h", "--help")  {puts opts.to_s ; exit 0}

loc = opts.parse!
@u ||='f'

begin

  puts CurrentTemp.new(loc,@u)

rescue 
  puts $!
  puts opts.to_s
  exit 1
end