Create dinamically hashes from string

hi, i have a cookie with various data, i want to convert it in an hash.
the data contain in the cookie are grouped by “;” and every group have a
summary (which i want to convert to a name variable hash, it’s separated
on the left items by a “-”) and various property:value (separated by

my_cookie =

def cookie_to_hashes(item)
if item
item.split(";").each do |group|
this_hash = {}
group_array = group.split("-")
group_array.last.split(",").each do |i|
items = i.split(":")
this_hash[items.first] = items.last
p this_hash


test = cookie_to_hashes(my_cookie)

the method i have write works fine, but now i want to retrieve the
hashes out of the method, using the names of the summary.
in practice i want to obtain this:

test = cookie_to_hashes(my_cookie)
puts @property1
puts @property2

how can i retrive an istance variable set with the summary string?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs