Created
July 15, 2013 02:01
-
-
Save igor47/5997028 to your computer and use it in GitHub Desktop.
a recursive to_hash for chef 11; also handles arrays inside the hash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment