Forum: Ruby check string format

Posted by ariv arasan (realarivarasan)
on 2012-11-21 13:54
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,
<key>=><value> or <key>=><hash format>
how could i achieve this?
main purpose is to make the string as a hash(not by using eval)
Posted by Jan E. (jacques1)
on 2012-11-21 18:03
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.
Posted by Ryan Davis (Guest)
on 2012-11-21 23:04
(Received via mailing list)
Parsing homework?
Posted by ariv arasan (realarivarasan)
on 2012-11-22 08:53
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.
Posted by Ryan Davis (Guest)
on 2012-11-22 09:32
(Received via mailing list)
On Nov 21, 2012, at 23:53 , ariv arasan <lists@ruby-forum.com> 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).
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.