ruby method to convert a hash to a string -


please me make method named hash_string takes hash , make string key/value pairs. example:

hash_string({id: 8, name: 'marry'}) # should return "id = 8, name = marry" 

i've tried same way before, are:

def hash_string(hash)   hash.to_s end 

and

def hash_string(hash)   set_value = hash.each {|key, value| puts "#{key} = #{value}" }   # set_value.join(",") end 

but did not work. please explain me, how can that?

replace each map, return value instead of outputting it, , you're done.

def hash_string(hash)   set_value = hash.map {|key, value| "#{key} = #{value}" }   set_value.join(",") end 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -