Ruby Hash >=() 函数
Hash#>=()是一个Hash类方法,用于比较两个Hash值。
语法。Hash.>=()
参数:哈希值
返回:真 – 如果a >= b,否则返回假
例子 #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"
# b
puts "Hash b >= c : #{b>=c}\n\n"
# c
puts "Hash a >= c : #{c>=a}\n\n"
输出:
Hash a >= b : false
Hash b >= c : true
Hash a >= c : false
例子 #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"
# b
puts "Hash b >= c : #{b>=c}\n\n"
# c
puts "Hash a >= c : #{c>=a}\n\n"
输出:
Hash a >= b : true
Hash b >= c : false
Hash a >= c : true