From: Jim Freeze Date: 2001-12-09T23:22:31+09:00 Subject: [ruby-talk:28029] dictionary.com modified for proxy Hi: Thanks for the dictionary.com script. This is a very nice way to demonstrate ruby. I have modified the code for machines behind a proxy server if anyone is interested. require "net/http" def usage STDERR.puts <<-USAGE Usage: #{File.basename $0} word Output is directed to STDOUT. USAGE end#usage if ARGV.size != 1 usage exit 1 end @url = "www.dictionary.com" @proxy_addr = 'your.proxy.here' @proxy_port = proxy_port_number def lookup(word) Net::HTTP::Proxy(@proxy_addr, @proxy_port).start( @url ) { |http| a = http.get("/cgi-bin/dict.pl?term=#{word}")[1] if ( /No entry found for/ =~ a ) puts "No entry found for '#{ARGV[0]}' - Suggestions:\n\n" while /(\w+)/ =~ $' puts $1 end else while a =~ // // =~ $' a = $' puts $`.gsub(/<.*?>/m) { |i| case i when "" "" when "" "\n" when "

" "" else "" end#case } end#while end#if } end#lookup lookup ARGV[0] ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- Today is a fine day for Ruby programming. http://www.freeze.org =========================================================