pass a block to your call to delete.
If the key you're wanting to delete is not found, the block runs, and its return value will be returned by delete.
myHash = { 1 => "One", 2 => "Two", 3 => "Three", 4 => "Four", 5 => "Five" }
myHash.delete( 6 ) { |key| puts "not found, bubba" }
Related examples in the same category