add key and value to hash ruby

To add a key and value to a hash in Ruby, you can use the following code:

hash = {}
hash[:key] = "value"

Explanation: 1. Create an empty hash using the curly braces {}. 2. Use the square brackets [] to specify the key and assign a value to it using the assignment operator =.

That's it! The key-value pair has been added to the hash.