ruby .each

Ruby Array.each方法 (Ruby Array.each method)

Array.each method can be easily termed as a method which helps you to iterate over the Array. This method first processes the first element then goes on the second and the process keeps on going on until the last element is not processed. This method is very important when it comes to carrying out the process of traversing the array. This method works in the way that each element of the instance of Array class is yielded to the block supplied to the method. The task is completed in a particular sequence. You will need to provide a temporary variable inside the pair of the disjoint symbol because you will be able to fetch the element with the help of that variable only. This simply means that first the value of an element is temporarily stored in that variable and it is stored ever since the next element does not come into the scene.

Array.each方法可以轻松地称为可帮助您遍历Array的方法 。 此方法首先处理第一个元素,然后继续处理第二个元素,然后继续进行直到没有处理最后一个元素。 在执行遍历数组的过程时,此方法非常重要。 该方法的工作方式是将Array类实例的每个元素都屈服到提供给该方法的块中。 该任务按特定顺序完成。 您将需要在不相交符号对中提供一个临时变量,因为您将只能在该变量的帮助下获取元素。 这仅意味着首先将元素的值临时存储在该变量中,并且由于下一个元素不进入场景就将其存储。

This operation or process does not bring any change in the actual values of Array elements.

此操作或过程不会使Array元素的实际值发生任何变化。

Syntax:

句法:

    Array.each { |var| #statements}

Parameter(s):

参数:

This method does not invite any type of argument.

此方法不邀请任何类型的参数。

Example 1:

范例1:

=begin
Ruby program to demonstrate Array.each
=end
# array declaration
Adc = ['Ruby','Includehelp.com','Ruby','C++','C#']
# counter intialization
cnt = 1
# Array.each method
Adc.each{ |ele|
puts "#{cnt} element is #{ele}"
cnt = cnt + 1
}

Output

输出量

1 element is Ruby
2 element is Includehelp.com
3 element is Ruby
4 element is C++
5 element is C#

The above code can be modified as,

上面的代码可以修改为

Example 2:

范例2:

=begin
Ruby program to demonstrate Array.each
=end
# array declaration
Adc = ['Ruby','Includehelp.com','Ruby','C++','C#']
# counter initialization
cnt = 1
Adc.each do |ele|
puts "#{cnt} element is #{ele}"
cnt = cnt + 1
end

Output

输出量

1 element is Ruby
2 element is Includehelp.com
3 element is Ruby
4 element is C++
5 element is C#

Explanation:

说明:

In the above two program codes, you can observe that the method named Array.each can be used in two different ways. Both the ways are quite understandable and their use depends upon your comfort. It is very clear with the help of output that the processing of Array elements starts from index 0 and finishes when the last element is being processed. You can never bring any change in the elements of Array with the help of this method because this method is one of the examples of non-destructive methods.

在以上两个程序代码中,您可以观察到名为Array.each的方法可以以两种不同的方式使用。 两种方式都是可以理解的,它们的使用取决于您的舒适度。 在输出的帮助下,很明显Array元素的处理从索引0开始,并在处理最后一个元素时结束。 借助于此方法,您永远无法对Array的元素进行任何更改,因为该方法是非破坏性方法的示例之一。

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

ruby .each

ruby .each_Ruby中带有示例的Array.each方法相关推荐

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

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

  2. ruby array_Ruby中带有示例的Array.select方法

    ruby array Array.select方法 (Array.select Method) In the last articles, we have seen how to iterate ov ...

  3. ruby array_Ruby中带有示例的Array.keep_if方法

    ruby array Ruby Array.keep_if方法 (Ruby Array.keep_if Method) In the last articles, we have studied th ...

  4. ruby array_Ruby中带有示例的Array.delete_if方法

    ruby array Ruby Array.delete_if方法 (Ruby Array.delete_if Method) In the last articles, we have studie ...

  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. ruby array_Ruby中带有示例的Array.index()方法

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

  8. ruby array_Ruby中带有示例的Array.sample()方法

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

  9. ruby array_Ruby中带有示例的Array.fill()方法(3)

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

最新文章

  1. java类与对象作用_Java类与对象
  2. 闪电网络运行过程中存在的一些问题
  3. java webproject中logback换配置文件的路径
  4. 关于maven依赖中的scopeprovided/scope使用
  5. 内核中断处理流程_处理中断
  6. oracle快捷语句框架中,Oracle框架:PL/SQL编程:
  7. ssm 新建拦截器_拦截器在springboot项目和ssm架构项目的应用
  8. 解决ajax无法给js全局变量赋值的问题
  9. x264编码参数大测试:05 subme与crf(g)
  10. tp框架 文件上传+excel表格导入
  11. 上海大华条码称代码_上海大华条码秤使用说明书样本
  12. 聚焦技术实战!MDCC 2016 移动开发者大会盛大开幕
  13. MATLAB 粒子群算法,例题与常用模版
  14. Vivado FIFO IP核设置
  15. React:setting Styles+ Radium
  16. LaTeX公式符号总结(Markdown适用)
  17. Ubuntu16.04系统nvidia显卡上图形界面及OpenGL环境搭建心得
  18. 梅科尔工作室-李柯增-鸿蒙笔记4
  19. 微信小程序会议OA-后台数据交互(首页)05
  20. 改进杂草算法求解WSN节点分布优化问题

热门文章

  1. ajax php接收不到数据库,PHP更新MySQL数据库与AJAX调用没有做任何事情
  2. 代码实现——MapReduce实现Hadoop序列化
  3. 【思维】Iranian ChamPions Cup
  4. 锁底层之内存屏障与原语指令
  5. Redis集群一致性Hash效果的代码演示
  6. parted分区介绍
  7. 64位操作系统上ArcGIS Server Manager页面不正常显示
  8. 开发人员应该用好的一些网站
  9. 数据库,XML,MDB --- 我们来TXT...
  10. c语言中 d 1是啥意思,空开D/C是什么意思?终于有人把它说清楚了!