All pastes #46726 Raw Edit

Anonymous

public ruby v1 · immutable
#46726 ·published 2006-03-23 18:52 UTC
rendered paste body
require 'net/http'class String  # Returns the contents of the string, assuming it is a url. Could be dangerous.  def get(body = nil)    url = get_url    http = get_http(url)        resp = http.get(url.path, body)        resp.body  end    # Attempts to parse <code>self</code> as a URL and then performs an HTTP POST on it, with  # the optional parameter as the body of the post.  Returns the result of the post.  def post(body = nil)    url  = get_url    http = get_http(url)        resp = http.post(url.path, body)        resp.code_type == Net::HTTPOK  end    private  def get_url    URI.parse self  end    def get_http(url)    Net::HTTP.new(url.host, url.port)  end  end