ruby - How to convert a hash to string -
input: contact = {"name" => "white", "age" => 22, "country" => "india"}
expected output: "age=22country=indianame=white"
one way using .map
contact = {"name" => "white", "age" => 22, "country" => "india"} contact.sort.map{|pair| pair.join('=')}.join => "age=22country=indianame=white"
edit: didn't notice implied sorting requirement in output.
Comments
Post a Comment