create dinamically hashes from string

A

Aldo Italo

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
comma):

my_cookie =
"my_first_group_title-property1:value1,property2:value2,property3:value3,property4:value4;
my_second_group_title-blue:property1:value1,property2:value2"


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
end
p this_hash
end
end

end



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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top