Check string format

i have a string
str=’{ “first” => “val”, “second” => { “a” => “aaa”, “b” => “bbbb” },
3=>“three”}’
i want to make an array from the string which should be like
arr = [“first => val”, “second => { a => aaa , b => bbbb }”, “3=>three”]
for that first,i want to check the string format,
=> or =>
how could i achieve this?
main purpose is to make the string as a hash(not by using eval)

Hi,

why do you use those strings in the first place? Where do they come
from?

Because I can’t think of any situation where it might make sense to pass
data structures around as strings of Ruby code.

Parsing homework?

its a kind of assignment for me “converting hash format string into hash
without using eval”. I tried a lot, couldn’t find solution. So i just
shared it in forum.

On Nov 21, 2012, at 23:53 , ariv arasan [email protected] wrote:

its a kind of assignment for me “converting hash format string into hash
without using eval”. I tried a lot, couldn’t find solution. So i just
shared it in forum.

Well, then, you might want to look up how to write a simple recursive
decent parser (RDP).

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