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 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" puts "Hash b < c : #{b<c}\n\n" puts "Hash a < c : #{c<a}\n\n" |
chevron_right
filter_none
Output :
Hash a < b : true Hash b < c : false Hash a < c : true
Example #2 :
# 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" puts "Hash b < c : #{b<c}\n\n" puts "Hash a < c : #{c<a}\n\n" |
chevron_right
filter_none
Output :
Hash a < b : false Hash b < c : true Hash a < c : false
Recommended Posts:
- Ruby | Hash value? method
- Ruby | Hash > method
- Ruby | Hash to_s method
- Ruby | Hash to_proc method
- Ruby | Hash select!() method
- Ruby | Hash reject method
- Ruby | Hash class >= method
- Ruby | Hash class <= method
- Ruby | String hash method
- Ruby | Hash reject! method
- Ruby | Hash length() method
- Ruby | Hash replace() method
- Ruby | Hash shift() method
- Ruby | Hash to_h method
- Ruby | Hash to_a method
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.



