Ruby Hash <=方法

Ruby Hash <=方法

Hash#<=() 是一个Hash类方法,用于比较两个Hash值。

语法。Hash.<=()

参数:哈希值

返回:true – 如果a <= b 否则返回false

例子 #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 : true

Hash b <= c : false

Hash a <= c : true

例子 #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 : false

Hash b <= c : true

Hash a <= c : false

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程