Ruby | Hash delete_if() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report delete_if() is a Hash class method which delete_if the key-value pair if the block condition is true Syntax: Hash.delete_if() Parameter: Hash array Block Condition Return: value from hash whose key is equal to delete_ifd key. Example #1: Ruby # Ruby code for delete_if() method # declaring Hash value a = { "a" => 100, "b" => 200 } # declaring Hash value b = {"a" => 100, "c"=>30} puts "delete_if a : #{a.delete_if{|key, value| value > 200 } }\n\n" puts "delete_if b : #{b.delete_if{|key, value| key == "a" } }\n\n" Output : delete_if a : {"a"=>100, "b"=>200} delete_if b : {"c"=>30} Example #2: Ruby # Ruby code for delete_if() method # declaring Hash value c = {"a" => 100, "c" => 300, "b" => 200} puts "delete b : #{c.delete_if{|key, value| key <= "b" } }\n\n" Output : delete b : {"c"=>300} Comment More infoAdvertise with us Next Article Ruby | Hash delete() function K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash delete() function delete() is an Hash class method which deletes the key-value pair and returns the value from hash whose key is equal to key. Syntax: Hash.delete() Parameter: Hash array Return: value from hash whose key is equal to deleted key. Example #1: Ruby # Ruby code for delete() method # declaring Hash value 1 min read Ruby | Hash eql? function Hash#eql?() is a Hash class method which checks whether the two Hash arrays are equal or not. Syntax: Hash.eql?() Parameter: Hash values Return: true - if two hash arrays are equal otherwise return false Example #1 : Ruby # Ruby code for Hash.eql?() method # declaring Hash value a = {a:100, b:200} # 2 min read 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 # Ruby code for clear() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b 1 min read Ruby | Hash empty? function Hash#empty?() is a Hash class method which checks whether the Hash array has any key-value pair. Syntax: Hash.empty?()Parameter: Hash valuesReturn: true - if no key value pair otherwise return false Example #1 :  Ruby # Ruby code for Hash.empty?() method # declaring Hash value a = {a:100, b:200} # 1 min read Ruby | Hash fetch function Hash#fetch() is a Hash class method which returns a value from the hash for the given key. With no other arguments, it will raise a KeyError exception. Syntax: Hash.fetch() Parameter: Hash values Return: value from the hash for the given key Example #1 : Ruby # Ruby code for Hash.fetch() method # de 2 min read Ruby | Hash flatten() function Hash#flatten() is a Hash class method which returns the one-dimensional flattening hash array. Syntax: Hash.flatten() Parameter: Hash values Return: one-dimensional flattening hash array Example #1 : Ruby # Ruby code for Hash.flatten() method # declaring Hash value a = {a:100, b:200} # declaring Has 2 min read Like