Ruby | Hash clear() function
clear() is an Hash class method which removes all the Hash elements from it.
Syntax: Hash.clear()
Parameter: Hashs to clear off
Return: Hash with all elements cleared
Example #1:
# Ruby code for clear() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # declaring Hash value c = {a:100} puts "clear a : #{a.clear()}\n\n" puts "clear b : #{b.clear()}\n\n" puts "clear b : #{c.clear()}\n\n" |
chevron_right
filter_none
Output :
clear a : {}
clear b : {}
clear b : {}
Example #2:
# Ruby code for clear() method # declaring Hash value a = { "a" => 100, "b" => 200 } # declaring Hash value b = {"a" => 100} # declaring Hash value c = {"a" => 100, "c" => 300, "b" => 200} puts "clear a : #{a.clear()}\n\n" puts "clear b : #{b.clear()}\n\n" puts "clear b : #{c.clear()}\n\n" |
chevron_right
filter_none
Output :
clear a : {}
clear b : {}
clear b : {}
Recommended Posts:
- Ruby | Hash key?() function
- Ruby | Hash dig() function
- Ruby | Hash key() function
- Ruby | Hash each() function
- Ruby | Hash eql? function
- Ruby | Hash any?() function
- Ruby | Set clear() function
- Ruby | clear() function
- Ruby | Hash compact() function
- Ruby | Hash keys() function
- Ruby | Vector hash() function
- Ruby | Time hash function
- Ruby | Hash has_key?() function
- Ruby | Hash to_s() function
- Ruby | Hash compare_by_identity () function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



