obj[]与obj.

Array.rassoc(obj)方法 (Array.rassoc(obj) Method)

In this article, we will study about Array.rassoc(obj) method. You all must be thinking the method must be doing something which is related to the insertion of a certain element. It is not as simple as it looks. Well, we will figure this out in the rest of our content. We will try to understand it with the help of syntax and demonstrating program codes.

在本文中,我们将研究Array.rassoc(obj)方法 。 大家都必须认为该方法必须执行与插入某个元素有关的操作。 它并不像看起来那么简单。 好吧,我们将在其余内容中解决这个问题。 我们将尝试借助语法并演示程序代码来理解它。

Method description:

方法说明:

This method is Public instance method and belongs to the Array class which lives inside the library of Ruby language. This method is used to check whether an object is a part of the particular Array instance or not and that Array instance cannot be a normal Array instance. If it is not normal, it means that Array instance is the Array of multiple Array instances or you can say that it the collection of multiple objects which are itself an object of Array class. Basically, it works for the Array instances whose elements are also Array instances. Let us go through the syntax and demonstrating the program codes of this method.

该方法是Public实例方法,属于Array类,它位于Ruby语言库中。 此方法用于检查对象是否为特定Array实例的一部分,并且该Array实例不能为普通Array实例。 如果不正常,则表示Array实例是多个Array实例的Array,或者可以说它是多个对象的集合,而这些对象本身就是Array类的对象。 基本上,它适用于其元素也是Array实例的Array实例。 让我们来看一下语法,并演示该方法的程序代码。

If you are thinking what it will return then let me tell you, it will return the first contained Array instance where it found the presence of the object. It will return "nil" if it hadn't found the object in any of the Arrays.

如果您在考虑它将返回什么,那么让我告诉您,它将返回找到对象存在的第一个包含的Array实例。 如果未在任何数组中找到对象,它将返回“ nil”。

Syntax:

句法:

    array_instance.assoc(obj)

Argument(s) required:

所需参数:

This method only takes one parameter and that argument is nothing but an object whose presence we want to check.

此方法仅使用一个参数,而该参数不过是一个要检查其存在性的对象。

Example 1:

范例1:

=begin
Ruby program to demonstrate rassoc method
=end
# array declarations
array1 = [1,"Ramesh","Apple",12,true,nil,"Satyam","Harish"]
array2 = ["Akul","Madhu","Ashok","Mukesh",788]
array3 = ["Orange","Banana","Papaya","Apricot","Grapes"]
arraymain = [array1,array2,array3]
puts "Enter the element you want to search"
ele = gets.chomp
if arraymain.rassoc(ele) != nil
puts "Element found in:"
print  arraymain.rassoc(ele)
else
puts "Element not found"
end

Output

输出量

RUN 1:
Enter the element you want to search
Ramesh
Element found in:
[1, "Ramesh", "Apple", 12, true, nil, "Satyam", "Harish"]
RUN 2:
Enter the element you want to search
Kiwi
Element not found

Explanation:

说明:

In the above code, you can find that the Array instance on which we have invoked rassoc() method is not any normal Array instance. It is the collection of multiple Array instances. It is returning the whole Array instance where it has found the object inputted by the user.

在上面的代码中,您可以发现我们调用rassoc()方法的 Array实例不是任何普通的Array实例。 它是多个Array实例的集合。 它返回找到用户输入对象的整个Array实例。

Example 2:

范例2:

=begin
Ruby program to demonstrate rassoc method
=end
# array declaration
array1 = ["Babita","Sabita","Ashok"]
puts array1.rassoc("Babita")

Output

输出量

No Output.

Explanation:

说明:

In the above, you can verify that rassoc() method does not work upon normal Array instances. It will return nil even if the object is a part of the Array instance.

在上面,您可以验证rassoc()方法不适用于普通Array实例。 即使对象是Array实例的一部分,它也将返回nil。

翻译自: https://www.includehelp.com/ruby/array-rassoc-obj-method-with-example.aspx

obj[]与obj.

obj[]与obj._Ruby中带有示例的Array.rassoc(obj)方法相关推荐

  1. obj[]与obj._Ruby中带有示例的Array.include?(obj)方法

    obj[]与obj. Ruby Array.include?(obj)方法 (Ruby Array.include?(obj) Method) In the previous articles, we ...

  2. ruby hash方法_Ruby中带有示例的Hash.rassoc(obj)方法

    ruby hash方法 Hash.rassoc(obj)方法 (Hash.rassoc(obj) Method) In this article, we will study about Hash.r ...

  3. ruby hash方法_Ruby中带有示例的Hash.invert方法

    ruby hash方法 Hash.invert方法 (Hash.invert Method) In this article, we will study about Hash.invert Meth ...

  4. ruby hash方法_Ruby中带有示例的Hash.select方法

    ruby hash方法 哈希选择方法 (Hash.select Method) In this article, we will study about Hash.select Method. The ...

  5. ruby array_Ruby中带有示例的Array.cycle()方法

    ruby array Array.cycle()方法 (Array.cycle() Method) In this article, we will study about Array.cycle() ...

  6. ruby array_Ruby中带有示例的Array.fill()方法(1)

    ruby array Array.fill()方法 (Array.fill() Method) In this article, we will study about Array.fill() me ...

  7. array.slice_Ruby中带有示例的Array.slice()方法

    array.slice Array.slice()方法 (Array.slice() Method) In this article, we will study about Array.slice( ...

  8. ruby array_Ruby中带有示例的Array.shuffle方法

    ruby array Array.shuffle方法 (Array.shuffle Method) In this article, we will study about Array.shuffle ...

  9. repeated_Ruby中带有示例的Array.repeated_combination()方法

    repeated Array.repeated_combination()方法 (Array.repeated_combination() Method) In this article, we wi ...

最新文章

  1. 实现O(1)时间复杂度带有min和max 函数的栈
  2. iPhone游戏编程教程一步步教你游戏开发
  3. 爆肝800000秒想出低成本无人驾驶测距
  4. 十道上市公司java面试试题
  5. mysql设置定位慢查询_mysql优化——定位慢查询
  6. C语言中的指针有什么作用
  7. jQuery Mobile基础 学习笔记
  8. Mechine Learing一:工程刚需的 “算法” 评估指标
  9. 数据库连接字符串的写法(参考)
  10. Java学习之反射机制及应用场景
  11. eclipse启动失败,报an error has occurred.see the log file错
  12. o'LogonUI Changer XP登陆界面更换器
  13. 前端实现Word在线预览
  14. ps中全选图层的方法
  15. Emacs 新闻组 之四 联系人管理
  16. [杜撰的故事]那天以后
  17. 【Unity小功能开发实战教程】在UI画布上画网格线
  18. GIT 中如何打标签
  19. awk、ruby计算总分排名,相同总分显示同一名次
  20. 【前端】使用nexus搭建本地npm仓库

热门文章

  1. elf 取路径_c – 获取主要可执行文件的ELF标题
  2. java 内存数据库 sql_ssm+redis +Maven用于内存数据库 (No Sql)入门demo
  3. python中改变参数值的方法_Python实现partial改变方法默认参数
  4. 一个路由器两个网段互通_如何判断两个IP地址是否在同一个网段?什么是子网掩码?...
  5. Promise实战AJAX封装
  6. Angularjs基础(十)
  7. 执行命令npm install XXX后仍然提示 Cannot find Module XXX
  8. jquery简单实现点击弹出层效果实例
  9. HTML5结合ajax实现文件上传以及进度显示
  10. 三个实用的提升网页性能技巧