I've been using the Rails framework these days, so I'll recap the early learning content that I just forgot.
hash = {}
hash[:name] = "I did it" #New keys not in the hash
hash[:name] = "Kanemura" #The value of the existing key is updated
puts hash[:name] #When outputting, the key name is a symbol in square brackets
hash = {name: "Kanemura"} #The final hash looks like this
arrays = []
hash = {name: "Kanemura"}
arrays << hash #Add to the array in hash form
puts arrays[0][:name]
#=>"Kanemura"
puts arrays
#=>{:name=>"Kanemura"}
When I was using Rails, I wondered if I was using hashes inside, but I completely forgot how to handle it in Ruby.
Recommended Posts