[chef] Re: Re: Re: converting attributes to ruby hash


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: converting attributes to ruby hash
  • Date: Wed, 6 Feb 2013 18:19:03 -0800


On Wednesday, February 6, 2013 at 4:03 PM, wrote:


Hi Seth,

Thanks for the help! Using [] notation rather than dot notation seems to have
fixed the problem with config.to_json generating unparsable json. I still have
two questions:

1) is `JSON.parse(config.to_json)` the correct way to get a ruby hash out of an
attribute? should `to_hash` accept a parameter for recursion? what's the point
of `.to_hash` anyway if it doesn't convert attributes into a hash…?
2) is dot notation deprecated?

Thanks again,
--Igor
The read-only/immutable merged attributes will convert to a regular Mash if you call #dup. This is a bit kludgy but works with the intent of #dup, to get a copy of the thing so you can modify it without changing the original. The conversion is mostly deep, in that hashes and arrays will get converted to new, mutable copies, but mutating values might change the originals.

HTH,

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§