ruby 生成哈希值_哈希 = Ruby中的运算符

news/2024/7/10 0:34:45 标签: java, python, 数据结构, 算法, vue

ruby 生成哈希值

In the last article, we have seen how we can compare two hash objects with the help of > operator? ">" method is a public instance method defined in Ruby's library.

在上一篇文章中,我们看到了如何在>运算符的帮助下比较两个哈希对象? “>”方法是Ruby的库中定义的公共实例方法。

In this article, we will see the implementation of the ">=" operator. The working is pretty clear with the help of its name. It is not as simple as it seems. We will figure it out in the content of this article. We will understand it with the help of syntaxes and demonstrating program codes.

在本文中,我们将看到“> =”运算符的实现 。 借助其名称,工作非常清晰。 它并不像看起来那么简单。 我们将在本文的内容中找到答案。 我们将借助语法和演示程序代码来理解它。

Method description:

方法说明:

This method is a public instance method that is defined in Ruby's library especially for Hash class. This method works in a way that it carries out a comparison between two different hashes and returns a Boolean value. The method returns true when the second hash is a subset of first hash and returns false if it is not the subset of the first Hash instance. It returns true even if the second hash object is equal to the first hash object. Being a subset simply means to have all those elements which are present in another Hash object.

此方法是在Ruby的库中定义的公共实例方法,特别是针对Hash类。 该方法的工作方式是在两个不同的哈希值之间进行比较并返回一个布尔值。 当第二个哈希是第一个哈希的子集时,该方法返回true;如果它不是第一个Hash实例的子集,则返回false。 即使第二个哈希对象等于第一个哈希对象,它也会返回true。 作为子集仅意味着拥有所有存在于另一个Hash对象中的所有元素。

Syntax:

句法:

    Hash >= Hash_object -> true or false

Parameter(s) required:

所需参数:

This method does not require any argument.

此方法不需要任何参数。

Example 1:

范例1:

=begin
  Ruby program to demonstrate >= operator
=end	

hash1= {"color"=> "Black", "object"=>"phone", "love"=>"mom","fruit"=>"Kiwi","vege"=>"potato"}

hash2= {"color"=> "Black", "object"=>"phone", "love"=>"mom","fruit"=>"Kiwi","vege"=>"potato"}

if(hash1>=hash2)
	puts "hash2 is a subset of or equal to hash1"
else
	puts "hash2 is not a subset of or equal to hash1"
end

Output

输出量

hash2 is a subset of or equal to hash1

Explanation:

说明:

In the above code, you can simply observe that the method has returned true inside the if the condition that is because the message is printed as "hash2 is the subset of or equal to hash1". This happened because hash1 is equal to hash2. The method must have returned true even if hash2 is the subset of hash1. This is the simple meaning of the subset.

在上面的代码中,您可以简单地观察到,如果条件是因为消息被打印为“ hash2是hash1或等于hash1的子集 ”,则该方法在true内返回了true。 发生这种情况是因为hash1等于hash2。 即使hash2是hash1的子集,该方法也必须返回true。 这是子集的简单含义。

Example 2:

范例2:

=begin
  Ruby program to demonstrate >= operator
=end	

hash1 ={"color"=> "Black", "object"=>"phone", "love"=>"mom","fruit"=>"Kiwi","vege"=>"potato"}

hash2={"color"=>"Black","object"=>"phone","love"=>"mom","fruit"=>"Kiwi","vege"=>"potato","o"=>"nil"}

if(hash1>=hash2)
	puts "hash2 is a subset of or equal to hash1"
else
	puts "hash2 is not a subset of or equal to hash1"
end

Output

输出量

hash2 is not a subset of or equal to hash1

Explanation:

说明:

In the above code, you can simply observe that the method has returned false inside the if the condition that is because the message is printed as "hash2 is not a subset of or equal to hash1". This happened because hash2 is not having all the elements which are present in hash1 or it is not equal to hash1. This is the simple meaning of the subset.

在上面的代码中,您可以简单地观察到,如果条件是因为消息被打印为“ hash2不是hash1或不等于hash1”的子集 ,则该方法在false内返回了false。 发生这种情况是因为hash2并不具有hash1中存在的所有元素,或者它不等于hash1。 这是子集的简单含义。

翻译自: https://www.includehelp.com/ruby/hash-greater-than-or-equal-to-operator.aspx

ruby 生成哈希值


http://www.niftyadmin.cn/n/1253989.html

相关文章

clock skew, jitter, glitch

clock skew指的是clock经过不同的路径之后产生的相位上的偏差; clock jitter指的是clock频率上的抖动; glitch指的是信号毛刺; duty cycle指的是占空比转载于:https://www.cnblogs.com/lybinger/p/10144918.html

查询计算机系学生的详细记录,实验三_数据库的简单查询和连接_.doc

实验三_数据库的简单查询和连接_实验三 数据库的简单查询和连接查询实验目的及要求掌握SELECT语句的基本语法;熟练掌握表的数据简单查询、数据排序;熟练掌握表的连接查询的表示;掌握等值连接与非等值连接、自身连接、外连接以及复合条件连接操…

多模块调用Service失败

最近在搭一个基础架构,整合项目。 在做多模块中调用的时候,在Autowired的时候找不到service的bean。 解决方案: 需要在启动类加入扫描 SpringBootApplication(scanBasePackages {"com.cloud.*","com.redis.*"})开源项目…

中职计算机管理总结,中职计算机教师工作总结.docx

文档介绍:中职计算机教师工作总结[模版仅供参考,切勿通篇使用]1本学年,我任教学校121、131班的计算机应用基础教学,同时兼任学校的、机房维护、德育等工作。在各位领导和老师的热心支持和帮助下,我认真做好教学工作&am…

【NLP】HanLP环境

1、参考:https://github.com/hankcs/pyhanlp 2、问题: C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-u617cfx3\jpype1\setup.py:173: FeatureNotice: Turned ON Numpy support for fast Java array access FeatureNotice) building _jpype extensi…

计算机操作系统第六章答案,计算机操作系统第六章节.ppt

计算机操作系统第六章节.ppt (295页)本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!49.9 积分第六章 虚拟存储器Evaluation only.Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.Co…

python 创建嵌套列表_在Python中创建嵌套目录

python 创建嵌套列表Creating multiple or nested directories in python should be implemented considering various error scenarios like, 应该考虑各种错误情况,例如在python中创建多个目录或嵌套目录 , Does the parent directory exist? 父目录…

python基础 继承

继承: 当多个类出现大量相同的代码的时候使用继承写一个猫类属性:姓名、年龄、颜色、性别行为:吃饭、睡觉、抓老鼠 写一个狗类属性:姓名、年龄、颜色、性别行为:吃饭、睡觉、看门有儿子、父亲、爷爷这种关系的一般叫做…