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

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -