AndreZimpel AndreZimpel - 2 years ago 183
Ruby Question

Dot notation to arrays

I got a string

and an object like this:

"body"=>"body text",
"tileBlock"=>{"title"=>"Home", "tag"=>{"title"=>"home", "id"=>45}, "active"=>true}

Is there a way to transform
to something like

Answer Source

You can use Enumerable#inject, take str="tileBlock.tag.title".

str.split(".").inject(object) { |m, x| m[x] }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download