Get and Post at the same time

Here's a script to retrieve Get and Post as the same time. I've had a
look for one as I needed it, but didn't find anything.

If someone finds it useful, great. If someone can tell me how it is
terrible Ruby code and how to make it better, that would be cool too
:slight_smile:

Douglas

class GetPostRequest
  
  include Singleton
  
  attr_reader :raw_get, :raw_post
  attr_reader :get, :post, :request
  
  # data from QUERY_STRING and $stdin
  def initialize
    @get = @post = Hash.new
    if ENV['QUERY_STRING']
      @raw_get = ENV['QUERY_STRING']
      @get = CGI::parse(@raw_get)
    end
    if ENV['REQUEST_METHOD'] == 'POST'
      @raw_post = $stdin.gets.strip
      @post = CGI::parse(@raw_post)
    end
    @request = @post.merge(@get) # get wins
  end
  
  # combined Get and Post
  def [](key)
    @request[key]
  end
  
end