From: Philip Mak Date: 2003-06-17T22:35:53+09:00 Subject: URL class; is this worth submitting to RAA? Before Ruby, I did a lot of web application programming in Perl using Apache::ASP. Apache::ASP has a method, $Server->URL(), which constructs a URL for me. I missed this capability in Ruby, so I made my own class which does this. Is this worth submitting to the RAA? It seems awfully simple. Although pretty useful, at least for me. # Constructs a URL from a query hash. # # Example: # # irb> URL.make('http://test.com/', {'login' => 'pmak', 'name' => 'Philip Mak', 'numbers' => [1,2,3]}) # "http://test.com/?name=Philip%20Mak;login=pmak;numbers=1;numbers=2;numbers=3" require 'uri' class URL def self.make(base, args = {}) args = args.delete_if { |k, v| v.nil? } if args.empty? base else "#{base}?#{ args.to_a.collect { |k, v| v.is_a?(Array) ? v.collect { |vn| "#{URI.escape(k.to_s)}=#{URI.escape(vn.to_s)}" }.join(';') : "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join(';') }" end end end