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


Chronological Thread 
  • From: Igor Serebryany < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: converting attributes to ruby hash
  • Date: Thu, 7 Feb 2013 09:20:59 -0800

On Wed, Feb 6, 2013 at 6:19 PM, Daniel DeLeo < " target="_blank"> > wrote:
> 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.

Hi Daniel, 

Thanks for the reply. I don't think what you're saying is true. Here is an example from a chef-shell session showing why:

chef > node.default["test"] = {"t" => {"bob"=>5}}
 => {"t"=>{"bob"=>5}} 
chef > t = node["test"]
 => {"t"=>{"bob"=>5}} 
chef > t.class
 => Chef::Node::ImmutableMash 
chef > h = t.dup
 => {"t"=>{"bob"=>5}} 
chef > h.class
 => Mash 
chef > h["t"].class
 => Chef::Node::ImmutableMash 

You can see that t.class is an immutable mash. Running dup on t indeed converts the top level to a plain mash, but the nested attributes remain immutable mashes. Is this a bug that I should be reporting to opscode?

--Igor



Archive powered by MHonArc 2.6.16.

§