Mega Code Archive

 
Categories / Ruby / Hash
 

Deleting and Clearing a Hash

# You can delete key-value pairs from a hash with the delete method.  myHash = { 1 => "One", 2 => "Two", 3 => "Three", 4 =>"Four", 5 => "Five" } # I'll delete the pair identified by key 5: myHash.delete( 5 ) # => "Five"