To add a key-value pair to a map in Ruby, you can use the []
method or store
method. Here's an example:
main.rb154 chars6 lines
In the example above, we have a my_map
hash that contains a few key-value pairs. To add a new key-value pair, we can use either the []
method or store
method, followed by the key and value we want to add.
After adding the new key-value pairs, we print the updated my_map
hash using puts
. The output shows that the new key-value pairs have been successfully added to the hash.
gistlibby LogSnag