Reputation: 1695
I have one yml file.. Its structure is as follows.
en:
hello: "Hello world"
menu:
profile: "My Profile"
my_risk: "My Risk"
header:
profile: "My Profile"
my_risk: "My Risk"
And when I am able to get the value of yml file using
yml_content = YAML.load_file('config/locales/en.yml')
p yml_content['en']
What i want to know is how to get the value profile
alone which is inside menu
of en
Also i want to know whether we can add a new object like my_abc: "ABC"
inside menu
using ruby.
Thanks in advance
Upvotes: 1
Views: 153
Reputation: 37409
When you parse a YAML you get a Hash. So to get into an inner element, all you need to do is:
p yml_content['en']['menu']['profile']
# => "My Profile"
Also, since it is a hash, all you need to do to add to it, is simply assign a new key-value to it:
yml_content['en']['menu']['my_abc'] = "ABC"
Upvotes: 3