How to build a URI object with request arguments by passing a hash?
I can generate a request with:
URI::HTTPS.build(host: 'example.com', query: "a=#{hash[:a]}, b=#{[hash:b]}")
which generates
https://example.com?a=argument1&b=argument2
however, I think that building a query string for many arguments would be unreadable and difficult to maintain. I would like to build a query string by passing a hash. As in the example below:
hash = { a: 'argument1', b: 'argument2'
which raises
NoMethodError: undefined method `to_str' for {:a=>"argument1", :b=>"argument2"}:Hash
Is it possible to build a query string based on a hash using api uri? I do not want the monkey file hash object ...
source share