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?