ruby - What is the best way to rewrite this code (Line is too long) -
i checking code rubocop , warning code:
def questions_from_time_by_page(t, pagesize, page) "#{@base_url}questions?pagesize=#{pagesize}&page=#{page}&fromdate=#{t}&site=stackoverflow&key=#{@key}" end
lib/stackify.rb:99:81: c: line long. [108/80] "#{@base_url}questions?pagesize=#{pagesize}&page=#{page}&fromdate=#{t}&site=stackoverflow&key=#{@key}"
what best way rewrite it?
split line multiple lines ?
def questions_from_time_by_page(t, pagesize, page) "#{@base_url}questions?pagesize=#{pagesize}&page=#{page}" + "&fromdate=#{t}&site=stackoverflow&key=#{@key}" end
or may there better way?
you can call to_query
on hash take care of url encoding etc. maybe this:
params = { :a => "http://google.com", :b => 123 } url = "http://example.com?#{params.to_query}"
this produces "http://example.com?a=http%3a%2f%2fgoogle.com&b=123"
tell me if solves issue.
Comments
Post a Comment