zemax微透镜阵列示例

阵列反向! 方法 (Array reverse! Method)

In this article, we will study about Array.reverse! method. You all must be thinking the method must be doing something related to reversing certain elements as we have done in the case of Array.reverse! method. 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.reverse! 方法 。 大家都必须认为该方法必须像在Array.reverse情况下所做的那样与反转某些元素有关! 方法。 它并不像看起来那么简单。 好吧,我们将在其余内容中解决这个问题。 我们将尝试借助语法并演示程序代码来理解它。

Method description:

方法说明:

This method is a public instance method and defined for the Array class in Ruby's library. This method works in a way that reverses the content or objects present inside the Array instances. It traverses the Array elements in the way that the last element is considered to be first and the first object is considered to be the last element of the object of Array instance. Array.reverse is a destructive method where the changes created by this method would impact the actual order of the Self Array instance and these changes are permanent.

该方法是一个公共实例方法,为Ruby库中的Array类定义。 此方法的工作方式是反转Array实例中存在的内容或对象。 它以以下方式遍历Array元素:将最后一个元素视为第一个元素,将第一个对象视为Array实例对象的最后一个元素。 Array.reverse是一种破坏性方法,其中此方法创建的更改将影响Self Array实例的实际顺序,并且这些更改是永久的。

Syntax:

句法:

    Array_instance.reverse! -> new_array

Argument(s) required:

所需参数:

This method does not require any argument. Reversing the Array instance does not require anything rather than the Array instance itself.

此方法不需要任何参数。 反转Array实例不需要什么,只需要Array实例本身即可。

Example 1:

范例1:

=begin
Ruby program to demonstrate reverse! method
=end
# array declaration
Lang = ["C++","Java","Python","Html","Javascript","php","Ruby","Kotlin"]
puts "Array reverse! implementation."
print Lang.reverse!
puts ""
puts "The first element of the Array is: #{Lang[0]}"
puts "Array elements are:"
print Lang

Output

输出量

Array reverse! implementation.
["Kotlin", "Ruby", "php", "Javascript", "Html", "Python", "Java", "C++"]
The first element of the Array is: Kotlin
Array elements are:
["Kotlin", "Ruby", "php", "Javascript", "Html", "Python", "Java", "C++"]

Explanation:

说明:

In the above code, you can observe that we are reversing the contents of Array class instance with the help of Array.reverse! method. You can observe that after reversing the contents, the first element is "Kotlin" because this method is a destructive method and creates changes in the actual arrangements of contents in Array instance.

在上面的代码中,您可以观察到借助Array.reverse ,我们正在反转Array类实例的内容 方法 。 您可以观察到,在反转内容之后,第一个元素是“ Kotlin”,因为此方法是一种破坏性方法,会在Array实例中实际更改内容的排列方式。

Example 2:

范例2:

=begin
Ruby program to demonstrate reverse! method
=end
# array declaration
Table = [2,4,6,8,10,12,14,16,18,20]
puts "Array reverse! implementation"
print Table.reverse!
puts ""
puts "The first element of the Array is: #{Table.first}"
puts "Array elements are:"
print Table

Output

输出量

Array reverse! implementation
[20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
The first element of the Array is: 20
Array elements are:
[20, 18, 16, 14, 12, 10, 8, 6, 4, 2]

Explanation:

说明:

In the above code, you can observe that this method works on Integer Array as well and we are reversing the contents of Array class instance with the help of Array.reverse! method. You can observe that after reversing the contents, the first element is 20 because this method is destructive and creates changes in the actual arrangements of contents in the Array instance.

在上面的代码中,您可以观察到该方法也适用于Integer Array,并且借助于Array.reverse ,我们正在反转Array类实例的内容 方法 。 您可以观察到,在反转内容之后,第一个元素为20,因为此方法具有破坏性,并会更改Array实例中内容的实际排列。

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

zemax微透镜阵列示例

zemax微透镜阵列示例_阵列反向! Ruby中的示例方法相关推荐

  1. _.uniq_在Ruby中使用Array.compact和Array.uniq方法从Array中移除元素

    _.uniq Ruby Array.compact和Array.uniq方法 (Ruby Array.compact and Array.uniq Methods) In the last artic ...

  2. as_hash ruby_Hash.merge(other_hash)方法与Ruby中的示例

    as_hash ruby Hash.merge(other_hash)方法 (Hash.merge(other_hash) Method) In this article, we will study ...

  3. ruby hash添加数据_如何在Ruby中向Hash添加元素?

    ruby hash添加数据 Before going through the ways to add elements to the hash instances, let us understand ...

  4. 二叉树 迭代 前 中 后_如何在Ruby中使用数组迭代计算二叉树的高度

    二叉树 迭代 前 中 后 Data structures and algorithms are the heart and soul of computer science and software. ...

  5. Ruby中带有示例的Hash.key?(value)方法

    Hash.key?(value)方法 (Hash.key?(value) Method) In this article, we will study about Hash.key?(value) M ...

  6. ruby 生成哈希值_如何检查Ruby中是否存在哈希键?

    ruby 生成哈希值 We know that Hashes are the instances which are the combination of keys and their values. ...

  7. 如何在Ruby中使用数组方法

    介绍 (Introduction) Arrays let you represent lists of data in your programs. Once you have data in an ...

  8. 雄迈sdk 使用示例_使用增强的API,示例代码和SDK自定义支付解决方案

    雄迈sdk 使用示例 As developers build sites for merchants, we know that payment processing capabilities are ...

  9. ruby中的回调方法和钩子方法

    在ruby中,当某些特定的事件发生时,将调用回调方法和钩子方法.事件有如下几种: 调用一个不存在的对象方法 类混含一个模块 定义类的子类 给类添加一个实例方法 给对象添加一个单例方法 引用一个不存在的 ...

最新文章

  1. Matlab百度中Cell(单元数据)的用法
  2. smarty学习——编程知识
  3. python网络编程基础(线程与进程、并行与并发、同步与异步、阻塞与非阻塞、CPU密集型与IO密集型)...
  4. python3精要(51)-json
  5. jboss 配置上下文路径_为单个Web应用程序配置多个上下文根– JBoss
  6. jquery获取java对象的属性_jQuery - 获得内容和属性
  7. Python基础第二十天:线程
  8. SharePoint 2007有性能问题? 先试试这篇.
  9. 计算机关机的界面,修改计算机关机界面_生活与休闲
  10. icem网格数和节点数_ansys中划分网格后,如何查看单元数和节点数
  11. 罗永浩发声:我的努力很可能失败 但好产品一定要赢
  12. HDU - 5510 Bazinga
  13. Google 在遗忘权下删除了超过 17 万链接
  14. 子平真诠释疑笔记(五)
  15. 极速office(excel)如何查找出重复内容
  16. UEFI Specification 第一章 引言(基于UEFI_Spec_2_9_2021_03_18)
  17. 内网渗透之CFS三层靶场渗透
  18. 如何制作Excel斜线表头
  19. 计算机管理创建扩展分区,win7系统怎么创建磁盘管理扩展分区
  20. Oracle 系统函数

热门文章

  1. 手机计算机数字显示在桌面上,手机计算器有哪些使用方法
  2. java的文本框如何回车键触发按钮_java回车触发按钮的代码
  3. JSON 使用 教程
  4. json-schema 可视化编辑器发布了
  5. 开发VUE使用第三库,发现有bug怎么办?
  6. java.lang.Error: Unresolved compilation problems
  7. JAVA比较两个List集合的方法
  8. 2018年各大互联网前端面试题五(今日头条)
  9. 元素分类--块级元素(特点:独占一行, 宽高边距可改)
  10. UITableViewCell 选中的状态小技巧