I am new to ruby and wanted to know if this is possible. Suppose I have a file with different blocks like this
fruits[tomato=1,orange=2]
greens[peas=2,potato=3]
I have parsed this file and stored it into a hash like this
{"fruits"=>{"tomato"=>"1", "orange"=>"2"}, "greens"=>{"potato"=>"3", "peas"=>"2"}}
And I also know how to access the different parts of the hash. But suppose if want to make it something like this
fruits.tomato # 1
fruits.orange # 2
(Like an object with tomato and orange being its variables)
The catch here is suppose I don't know if the file is going to contain fruits and greens, it could contain a different group called meat. I know this dynamic problem can be solved if I insert everything into a hash with the key as group name and value will be another hash. But can this be done with the example of fruit.tomato or fruits.orange I provided above(Probably by declaring it in a class but I am not sure how to dynamically add class vars in ruby or if that is even possible as I am new to the language).