associative array in rails
# Step 1: Create an associative array (hash) in Ruby
my_hash = {}
# Step 2: Add key-value pairs to the hash
my_hash["name"] = "John"
my_hash["age"] = 25
my_hash["city"] = "New York"
# Step 3: Access values using keys
name = my_hash["name"]
age = my_hash["age"]
city = my_hash["city"]
# Step 4: Output the values
puts "Name: #{name}"
puts "Age: #{age}"
puts "City: #{city}"
This Ruby code demonstrates the creation of an associative array (hash) and the addition of key-value pairs. It also shows how to access values using keys and output the information.