Ruby | Hash > method Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Hash#>() is a Hash class method compares two Hash values. Syntax: Hash.>() Parameter: Hash values Return: true - if a > b otherwise return false Example #1 : Ruby # Ruby code for Hash.>() 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} # COMPARING TWO Hash VALUES puts "Hash a > b : #{a>b}\n\n" # b puts "Hash b > c : #{b>c}\n\n" # c puts "Hash a > c : #{c>a}\n\n" Output : Hash a > b : false Hash b > c : true Hash a > c : false Example #2 : Ruby # Ruby code for Hash.>() 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} # COMPARING TWO Hash VALUES puts "Hash a > b : #{a>b}\n\n" # b puts "Hash b > c : #{b>c}\n\n" # c puts "Hash a > c : #{c>a}\n\n" Output : Hash a > b : true Hash b > c : false Hash a > c : true Comment More infoAdvertise with us Next Article Ruby | Hash < method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash class >= method Hash#>=() is a Hash class method which compares two Hash values. Syntax: Hash.>=() Parameter: Hash values Return: true - if a >= b otherwise return false Example #1 : Ruby # Ruby code for Hash.>=() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, 2 min read Ruby | Hash to_a method Hash#to_a() is a Hash class method which gives a nested array of the key-value pair. Syntax: Hash.to_a() Parameter: Hash values Return: array representation of the hash Example #1 : Ruby # Ruby code for Hash.to_a() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c 2 min read Ruby | Hash to_h method Hash#to_h() is a Hash class method which returns the self - hash representation of the hash Syntax: Hash.to_h() Parameter: Hash values Return: self object Example #1 : Ruby # Ruby code for Hash.to_h() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # 1 min read Ruby | Hash < method Hash#<() is a Hash class method which compares two Hash values. Syntax: Hash.<() Parameter: Hash values Return: true - if a < b otherwise return false Example #1 : Ruby # Ruby code for Hash.<() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:2 1 min read Ruby | Hash to_s method Hash#to_s() is a Hash class method which gives the string representation of the hash. Syntax: Hash.to_s() Parameter: Hash values Return: string representation of the hash. Example #1 : Ruby # Ruby code for Hash.to_s() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100 1 min read Ruby | Hash values_at method Hash#values_at() is a Hash class method which returns the array containing the values corresponding to keys. Syntax: Hash.values_at() Parameter: Hash values_at Return: array containing the values corresponding to keys. Example #1 : Ruby # Ruby code for Hash.values_at() method # declaring Hash value 1 min read Like