# File lib/stella/core_ext.rb, line 498 def dump(format) respond_to?(:"to_#{format}") ? send(:"to_#{format}") : raise("Unknown format") end
Courtesy of Julien Genestoux
# File lib/stella/core_ext.rb, line 471 def flatten params = {} stack = [] each do |k, v| if v.is_a?(Hash) stack << [k,v] elsif v.is_a?(Array) stack << [k,Hash.from_array(v)] else params[k] = v end end stack.each do |parent, hash| hash.each do |k, v| if v.is_a?(Hash) stack << ["#{parent}[#{k}]", v] else params["#{parent}[#{k}]"] = v end end end params end
Courtesy of Julien Genestoux See: stackoverflow.com/questions/798710/how-to-turn-a-ruby-hash-into-http-params NOTE: conflicts w/ HTTParty 0.7.3 when named “to_params”
# File lib/stella/core_ext.rb, line 505 def to_http_params params = '' stack = [] each do |k, v| if v.is_a?(Hash) stack << [k,v] elsif v.is_a?(Array) stack << [k,Hash.from_array(v)] else params << "#{k}=#{v}&" end end stack.each do |parent, hash| hash.each do |k, v| if v.is_a?(Hash) stack << ["#{parent}[#{k}]", URI::Escape.escape(v)] else params << "#{parent}[#{k}]=#{URI::Escape.escape(v)}&" end end end params.chop! params end
Generated with the Darkfish Rdoc Generator 2.