1. Conclusion </ b>
2. What is a double hash </ b>
3. How to use </ b>
4. What I learned from here (used in case of error) </ b>
Use each method with double hashes and arrays!
The state where the hash is included in the hash In other words, it says the following!
student = {human: {gender: {name: 'John'}}}
I think the combination of hashes and arrays is easy!
students = [
{human: {gender: {name: 'John'}}},
{human: {gender: {name: 'Nick'}}},
{human: {gender: {name: 'Alan'}}},
]
Just put the one in 2. in the array and it will be the above. Then use the each method when calling the name. Otherwise you will not be able to call all the names.
1
students = [
{human: {gender: {name: 'John'}}},
{human: {gender: {name: 'Nick'}}},
{human: {gender: {name: 'Alan'}}},
]
students.each do |student|
puts sutudent[:human][:gender][:name]
end
<br>
Now you can call all the names.
Another method is the dig method.
2
(abridgement)
students.each {|student| puts student.dig(:human, :gender, :name)}
Because it's an array when you want to output all the names
I thought I should get the information of all the sequences (three information of [0] ~ [2]). Then, I thought it would be good to assign the three information to a variable and output it with puts, but I thought it was meaningless to release the array. Since each is a process that repeats the variables of the array one by one, it was a perfect method including dig.
Recommended Posts