In Ruby, you can remove a key-value pair from a Hash (also commonly referred to as a Map) using the delete
method.
Here's an example:
main.rb92 chars4 lines
In this example, we first create a Hash called my_map
with three key-value pairs. We then call the delete
method on this Hash with the key "b"
as an argument. This removes the key-value pair with key "b"
from my_map
.
Finally, we output the updated contents of my_map
using puts
. This outputs the remaining key-value pairs in the Hash after "b"
has been removed.
gistlibby LogSnag