Help - Hash.to_params


#1

This is my current implementation for Hash.to_params

If you have spare time, please help me optimize this.

Thanks.

class Hash
def to_params(parent = ‘’)
ret = ‘’
self.keys.each do |key|
if self[key].is_a? Hash
if parent == ‘’
ret += self[key].to_uri(key.to_s)
else
ret += self[key].to_uri(parent + “[#{key.to_s}]”)
end
else
if parent == ‘’
ret += “#{key}=#{self[key]}&”
else
ret += “#{parent}[#{key}]=#{self[key]}&”
end
end
end
return ret.chomp(’&’)
end
end


#2

what do you plan to use this for?

as it would seem url_for() would do just fine


#3

Keynan P. wrote:

what do you plan to use this for?

as it would seem url_for() would do just fine

How do I test url_for in script/console? I’m not exactly certain how it
works, and I’d like to test and see if it does what I want.

Thanks.