public
Created

a recursive to_hash for chef 11; also handles arrays inside the hash.

  • Download Gist
chef_to_hash.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class Chef
class Node
class ImmutableMash
def to_hash
h = {}
self.each do |k,v|
if v.respond_to?('to_hash')
h[k] = v.to_hash
elsif v.respond_to?('each')
h[k] = []
v.each do |i|
if i.respond_to?('to_hash')
h[k].push(i.to_hash)
else
h[k].push(i)
end
end
else
h[k] = v
end
end
return h
end
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.