I’m building a tree of html elements, class names and their counts.
How would I structure this code with the proper syntax?
$html = {
:p => [
{ 'quote' => 10 },
{ 'important' => 4 }
],
:h2 => [
{ 'title' => 33 },
{ 'subtitle' => 15 }
]
}
I’m confused by the nested hash syntax. Thanks for the help setting me straight.
After defining the HTML element you don’t assign another hash, but a list and from your question title I guess you want to nest another hash directly. Thus you do not start with a square bracket, but with another curly brace:
Which will print:
Take a look at the constructor documentation of Hash, there are different ways to initialize hashes, maybe you find a more intuitive one.