require 'net/http'

url = "http://tommyjohn.com"
url2 = "http://porkchop.club/"

def check_www(url)
  uri = URI.parse(url)
  res = Net::HTTP.get_response(uri)

  if res.code == "301" && res.header['location']
    puts "YEP! It redirects!"
  else
    puts "NOPE! Something is wrong..."
  end
end

check_www(url)
check_www(url2)

require 'net/http'

def check_www(url)
  uri = URI.parse(url)
  res = Net::HTTP.get_response(uri)

  if res.code == "301" && res.header['location']
    puts "YEP! It redirects!"
  else
    puts "NOPE! Something is wrong..."
  end
end

begin
  url = ARGV[0]
  check_www(url)
rescue Exception => error
  puts error.message
end

Read URL as an argument from the command line
Read URL as an argument from the command line

add begin rescue blog to print error messages
