# Chef::Node::Attribute trying to call Hash methods on Array types

**URL:** <https://discourse.chef.io/t/chef-node-attribute-trying-to-call-hash-methods-on-array-types/1636>\
**Category:** Chef Infra (archive)\
**Created:** [December 30, 2010, 12:58am UTC](https://discourse.chef.io/t/chef-node-attribute-trying-to-call-hash-methods-on-array-types/1636 "2010-12-30T00:58:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Duffy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/charles_duffy/32/793_2.png) [@Charles\_Duffy](https://discourse.chef.io/u/Charles_Duffy)\
**Post date:** [December 30, 2010, 12:58am UTC](https://discourse.chef.io/t/chef-node-attribute-trying-to-call-hash-methods-on-array-types/1636/1 "2010-12-30T00:58:27Z")

</div>

Howdy!

I’m trying to determine whether the following behavior constitutes a bug:

chef \> node.default[:foo] = []  
=\> []  
chef \> node.set[:foo] \<\< {:foo =\> “bar”}  
=\> {:foo=\>“bar”}  
chef \> node[:foo].each { |entry| puts entry[:foo] }  
NoMethodError: undefined method `keys' for []:Array from /usr/lib64/ruby/gems/1.8/gems/chef-0.9.12/lib/chef/node/attribute.rb:250:in`keys’  
from  
/usr/lib64/ruby/gems/1.8/gems/chef-0.9.12/lib/chef/node/attribute.rb:248:in  
`each' from /usr/lib64/ruby/gems/1.8/gems/chef-0.9.12/lib/chef/node/attribute.rb:248:in`keys’  
from  
/usr/lib64/ruby/gems/1.8/gems/chef-0.9.12/lib/chef/node/attribute.rb:243:in  
`get_keys' from /usr/lib64/ruby/gems/1.8/gems/chef-0.9.12/lib/chef/node/attribute.rb:129:in`each’  
from (irb):22  
from :0

This happens because Chef::Node::Attribute’s each instance calls get\_keys,  
which in turn calls keys, which isn’t available for an array.

Is there an idiom I should be using which would avoid this issue?
