Ruby | Hash member? function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Hash#member?() is a Hash class method which checks whether the given key is present in hash is not. Syntax: Hash.member?() Parameter: Hash values Return: true - if given key is present in hash otherwise return false Example #1 : Ruby # Ruby code for Hash.member?() 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} # member? Value puts "Hash a member? form : #{a.member?("a")}\n\n" puts "Hash b member? form : #{b.member?("c")}\n\n" puts "Hash c member? form : #{c.member?("a")}\n\n" Output : Hash a member? form : false Hash b member? form : false Hash c member? form : false Example #2 : Ruby # Ruby code for Hash.member?() 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} # member? Value puts "Hash a member? form : #{a.member?("a")}\n\n" puts "Hash b member? form : #{b.member?("c")}\n\n" puts "Hash c member? form : #{c.member?("a")}\n\n" Output : Hash a member? form : true Hash b member? form : false Hash c member? form : true Comment More infoAdvertise with us Next Article Ruby | Hash invert() function K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash merge function Hash#merge() is a Hash class method which combines two hash arrays and their content. Syntax: Hash.merge() Parameter: Hash values Return: combine two hash arrays Example #1 : Ruby # Ruby code for Hash.merge() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, 2 min read Ruby | Hash merge! function Hash#merge!() : merge!() is a Hash class method which can add the content the given hash array to the other. Entries with duplicate keys are overwritten with the values from each other_hash successively if no block is given. Syntax: Hash.merge!() Parameter: Hash values Return: add the content the gi 2 min read Ruby | Hash key?() function Hash#key?() is a Hash class method which checks whether the key corresponding to the value is present or not. Syntax: Hash.key?() Parameter: Hash values Return: true - if key corresponding to the value is present otherwise return false Example #1 : Ruby # Ruby code for Hash.key?() method # declaring 2 min read Ruby | Hash key() function Hash#key() is a Hash class method which gives the key value corresponding to the value. If value doesn't exist then return nil. Syntax: Hash.key() Parameter: Hash values Return: key corresponding to the value nil - If value doesn't exist Example #1 : Ruby # Ruby code for Hash.key() method # declarin 2 min read Ruby | Hash invert() function Hash#invert() is a Hash class method which gives the hash by reverting keys to values and values to key. Syntax: Hash.invert() Parameter: Hash values Return: hash by reverting keys to values and values to key Example #1 : Ruby # Ruby code for Hash.invert() method # declaring Hash value a = {a:100, b 2 min read Ruby | Matrix hash() function The hash() is an inbuilt method in Ruby returns the hash-code of the matrix. Syntax: mat1.hash()Parameters: The function does not accepts any parameter.Return Value: It returns the hash-code of the matrix. Example 1:Â Â Ruby # Ruby program for hash() method in Matrix # Include matrix require "matrix" 1 min read Like