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 code for Hash.<() method # declaring Hash valuea = {a:100, b:200} # declaring Hash valueb = {a:100, c:300, b:200} # declaring Hash valuec = {a:100} # COMPARING TWO Hash VALUESputs "Hash a < b : #{a<b}\n\n" puts "Hash b < c : #{b<c}\n\n" puts "Hash a < c : #{c<a}\n\n" |
Output :
Hash a < b : true Hash b < c : false Hash a < c : true
Example #2 :
# Ruby code for Hash.<() method # declaring Hash valuea = { "a" => 100, "b" => 200 } # declaring Hash valueb = {"a" => 100} # declaring Hash valuec = {"a" => 100, "c" => 300, "b" => 200} # COMPARING TWO Hash VALUESputs "Hash a < b : #{a<b}\n\n" puts "Hash b < c : #{b<c}\n\n" puts "Hash a < c : #{c<a}\n\n" |
Output :
Hash a < b : false Hash b < c : true Hash a < c : false
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.


