Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
convert a hash to html
def convert_hash_to_html(data)
html = "<dl>"
data.each do |key, val|
html << "<dt>#{key}</dt>"
if val.is_a? Hash
html << "<dd>#{convert_hash_to_html val}</dd>"
elsif val.is_a? Array
html << "<dd>#{convert_array_to_html val}</dd>"
else
html << "<dd>#{val}</dd>"
end
end
html << "</dl>"
end
def convert_array_to_html(data)
html = "<dl>"
data.each do |val|
if val.is_a? Hash
html << "<dd>#{convert_hash_to_html val}</dd>"
elsif val.is_a? Array
html << "<dd>#{convert_array_to_html val}</dd>"
else
html << "<dd>#{val}</dd>"
end
end
html << "</dl>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.