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:

=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.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378490.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378490.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378490.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

oracle平均活動會話數,Oracle11g r2的活動會話數問題解決

如果你在Oracle11g r2的活動會話數的實際操作中,你對Oracle11g r2的活動會話數有不解之處時,你可以通過以下的文章對其的實際應用與功能有所了解,以下是文章的具體介紹,望你瀏覽完以下的內容會有所收獲。在Oracle11g r2的活動會話…

請分析比較下列四種染料在相同濃度和相同溫度的水染液中的聚集度大小?

請分析比較下列四種染料在相同濃度和相同溫度的水染液中的聚集度大小? 標準答案: 染料聚集度從大到小的順序為:3〉1〉4〉2 比較1-4染料結構差異,1、2共軛體系較短,3、4共軛體系較長,1、3磺酸基在端部,2、4磺酸基在中間; 染料3共軛體系長,范德華力大,而水溶性磺酸基團…

分割范圍Codeforces Round #181 (Div. 2)

每日一貼,今天的內容關鍵字為分割范圍 標題鏈接 A ,B雖然是水題,但要是沒想清晰就易容掉進某個坑里。。 C:預處理出有所可能的和,然后個每個每和分給a b兩個數 D:競賽的時候標題沒看懂,題意就是說在一個n*n…

VC++動態鏈接庫深入淺出(轉)

1.概論  先來闡述一下DLL(Dynamic Linkable Library)的概念,你可以簡單的把DLL看成一種倉庫,它提供給你一些可以直接拿來用的變量、函數或類。在倉庫的發展史上經歷了“無庫-靜態鏈接庫-動態鏈接庫”的時代。 靜態鏈接庫與動態鏈…

智能車復工日記【6】:有bug的模糊PID記錄

目錄 系列文章DYY Warning算法參考鏈接:代碼.c文件.h文件調用方法希望有大佬能幫我指正錯誤之處。以后假如有機會的話再搞這個模糊吧,頭疼!!!系列文章 【智能車Code review】—曲率計算、最小二乘法擬合 【智能車Code review】——坡道圖像與控制處理 【智能車Code review…

車刀 matlab,可轉位車刀的結構

內容介紹原文檔由會員 違規屏蔽12 發布摘 要隨著有限元技術的快速發展,結構優化在航空航天、建筑、汽車、工程機械等領域的結構設計方面應用越來越廣泛。在刀具行業中,新型刀具材料不斷涌現,刀具的結構也在不斷發展,目前針對刀具的…

DtCms.Model.Advertising.cs

using System; namespace DtCms.Model {/// <summary>/// 廣告位實體類Advertising/// </summary>[Serializable]public class Advertising{public Advertising(){ }#region Modelprivate int _id;private string _title;private int _adtype;private string _adre…

分析染色溫度對染色熱力學性能和染色動力學性能的影響?實際生產時,染色溫度選擇應考慮哪些因素?舉例說明?并闡明實現低溫染色的原理。

分析染色溫度對染色熱力學性能和染色動力學性能的影響?實際生產時,染色溫度選擇應考慮哪些因素?舉例說明?并闡明實現低溫染色的原理。 答:染料的結構包括物理結構和化學結構,溫度高低會影響染料結構,影響染料在染浴中的狀態,染料的溶解、聚集、電離等性能,從而影響染…

c++stl和std_std :: replace()函數以及C ++ STL中的示例

cstl和stdC STL std :: replace()函數 (C STL std::replace() function) replace() function is a library function of algorithm header, it is used to replace an old value with a new value in the given range of a container, it accepts iterators pointing to the s…

《Two Dozen Short Lessons in Haskell》(二十)分數

《Two Dozen Short Lessons in Haskell》&#xff08;Copyright © 1995, 1996, 1997 by Rex Page&#xff0c;有人翻譯為Haskell二十四學時教程&#xff0c;該書如果不用于贏利&#xff0c;可以任意發布&#xff0c;但需要保留他們的copyright&#xff09;這本書是學習 Ha…

oracle 查詢不能重復,oracle – 如何防止在選擇查詢中選擇重復行?

我被賦予了從Oracle數據庫中選擇關鍵數據的任務,但我注意到我的select正在返回重復的行.我不需要它們用于我的報告但我不希望它們刪除它們.有人可以幫助只獲取我需要的數據.我嘗試了以下代碼,但這沒有用.SELECT distinct bbp.SUBCAR "Treadwell",bbp.BATCH_ID "…

數字圖像課程工程大作業分析

試題分析&#xff1a; 在連續的視頻中對火焰及水柱的軌跡檢測&#xff0c;效果如圖。 ** 提示&#xff1a; 1、火焰可利用亮度和顏色 2、水柱的軌跡需要先用背景差分獲得水柱的連通域&#xff0c;然后利用連通域上的像素點進行曲線的擬合&#xff0c;水槍的位置視為已知&#…

設計電子商務網站的10個技巧(轉自ITEye)

導讀&#xff1a;隨著先進科學技術的應用&#xff0c;人們無需外出逛幾個小時來“獵”東西&#xff0c;直接坐在家里就可以購買所需商品&#xff0c;支付服務費用。你只需一臺電腦就能搞定。人們習慣了周到的服務和漂亮的櫥窗&#xff0c;對網店的選擇也不例外。因此&#xff0…

分析酸對酸性染料染羊毛染色性能的影響?舉例說明酸性染料染羊毛時,如何選擇合適的染浴pH值?并說明原因。

分析酸對酸性染料染羊毛染色性能的影響?舉例說明酸性染料染羊毛時,如何選擇合適的染浴pH值?并說明原因。 標準答案: 羊毛屬于蛋白質纖維,屬于兩性纖維,酸影響羊毛的解離程度,帶電性及帶電量,影響熱力學性能。等電點以下,羊毛帶正電荷,與陰離子酸性染料之間存在靜電引…

ORACLE連接數據庫(備忘)

常用命令&#xff1a; conn sys/密碼 as sysdba 連接數據庫轉載于:https://www.cnblogs.com/jiangu66/archive/2013/05/01/3053787.html

stl swap函數_vector :: swap()函數以及C ++ STL中的示例

stl swap函數C vector :: swap()函數 (C vector::swap() function) vector::swap() is a library function of "vector" header, it is used to swap the content of the vectors, it is called with a vector and accepts another vector as an argument and swaps…

C++語法:vector的使用

【1】vector的創建與元素插入【2】vector元素的訪問【3】vector的基本使用技巧【4】vector的幾個重要操作【1】vector的創建與元素插入 std::vector<cv::Point> points; //vector容器中保存的類型是Point for (int i 0;i < 10;i) {float x rng.uniform(0, img.cols…

一、經含氟防水劑整理的織物主要存在的不足?

經含氟防水劑整理的織物主要存在的不足? 收集資料階段 含氟防水劑有哪些優缺點 一、含氟防水劑的優點 1、防水效果好,等級高。而無氟防水劑效果相對來說要差一些; 2、兼具防油的功能。無氟防水劑是不具備防油功能的; 3、穩定性好、與其他助劑的配伍好,工藝適應性強;有機…

Apache Web Login Authentication

Apache Web Login Authentication: Adding password protection to a web site using Apache web server authentication. AuthLDAPURL ldap://ldap.your-domain.com:389/ostooges?uid?subAuthLDAPBindDN "cnStoogeAdmin,ostooges"AuthLDAPBindPassword secret1Aut…

oracle中的with的用法,oracle中with子句的用法(轉)

語法&#xff1a;WITH query_name AS (subquery)[, query_name AS (subquery) ]...使用在主select關鍵字前&#xff0c;oracle將其當做一個內聯視圖或者臨時表使用。例子&#xff1a;1.最簡單的使用方法&#xff1a;如查詢部門名稱包含“A”的所有員工信息--with clausewith a …