日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 obj[]与obj._Ruby中带有示例的Array.rassoc(obj)方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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:

=beginRuby 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.chompif arraymain.rassoc(ele) != nilputs "Element found in:"print arraymain.rassoc(ele) elseputs "Element not found" end

Output

輸出量

RUN 1: Enter the element you want to searchRamesh Element found in: [1, "Ramesh", "Apple", 12, true, nil, "Satyam", "Harish"]RUN 2: Enter the element you want to searchKiwi 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:

=beginRuby 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)方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。