ruby array

Array.zip()方法 (Array.zip() Method)

In this article, we will study about Array.zip() Method. You all must be thinking the method must be doing something which is related to zipping values of the Array instance. 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.zip()方法 。 你们都必须认为该方法必须做的事情与Array实例的压缩值有关。 它并不像看起来那么简单。 好吧,我们将在其余内容中解决这个问题。 我们将尝试借助语法并演示程序代码来理解它。

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 it converts any argument into the Array object and then merges that Array instance with the elements of self array. This results in a sequence of Array.length n-element Array object where n is possibly more than the number of elements. The method will supply "nil" values if the size of any argument is less than the size of the initial Array. If you are providing a block then the block is called for each resulting Array object otherwise an Array of Arrays is returned or you can say that a multi-dimensional Array is returned.

该方法是一个公共实例方法,为Ruby库中的Array类定义。 此方法的工作方式是将任何参数转换为Array对象,然后将该Array实例与self数组的元素合并。 这将导致Array.length个 n元素Array对象的序列,其中n可能大于元素数。 如果任何参数的大小小于初始Array的大小,则该方法将提供“ nil”值。 如果要提供一个块,则为每个结果Array对象调用该块,否则将返回一个Array数组,或者可以说返回了一个多维Array。

Syntax:

句法:

    array_instance.zip(arg, ...) -> new_ary
array_instance.zip(arg, ...) { |arr| block } -> nil

Argument(s) required:

所需参数:

This method can take multiple objects as arguments.

此方法可以将多个对象用作参数。

Example 1:

范例1:

=begin
Ruby program to demonstrate zip method
=end
# array declaration
table = ["fatima","Sabita","Monica","Syresh","Kamish","Punish"]
table1 = ["Apple","Banana","Orange","Papaya"]
puts "Array zip implementation:"
puts "#{["abc","pqr"].zip(table,table1)}"
puts "Array instance : #{table}"

Output

输出量

Array zip implementation:
[["abc", "fatima", "Apple"], ["pqr", "Sabita", "Banana"]]
Array instance : ["fatima", "Sabita", "Monica", "Syresh", "Kamish", "Punish"]

Explanation:

说明:

In the above code, you can see that we are zipping the Array object with the help of Array.zip() method. This method is a non-destructive method and does not create any change in the actual Array instance.

在上面的代码中,您可以看到我们正在借助Array.zip()方法压缩Array对象。 此方法是一种非破坏性方法,不会在实际的Array实例中创建任何更改。

Example 2:

范例2:

=begin
Ruby program to demonstrate zip method
=end
# array declaration
table = ["fatima","Sabita","Monica","Syresh","Kamish","Punish"]
table1 = ["Apple","Banana","Orange","Papaya"]
puts "Array zip implementation:"
puts "#{table.zip(["Kuber","Kamesh"],table1)}"
puts "Array instance : #{table}"

Output

输出量

Array zip implementation:
[["fatima", "Kuber", "Apple"], ["Sabita", "Kamesh", "Banana"], ["Monica", nil, "Orange"], ["Syresh", nil, "Papaya"], ["Kamish", nil, nil], ["Punish", nil, nil]]
Array instance : ["fatima", "Sabita", "Monica", "Syresh", "Kamish", "Punish"]

Explanation:

说明:

In the above code, you can see that we are zipping the Array object with the help of the Array.zip() method. This method is a non-destructive method and does not create any change in the actual Array instance.

在上面的代码中,您可以看到我们在Array.zip()方法的帮助下压缩Array对象。 此方法是一种非破坏性方法,不会在实际的Array实例中创建任何更改。

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

ruby array

ruby array_Ruby中带有示例的Array.zip()方法相关推荐

  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. 解决android 编译失败 Unexpected scopes found in folder
  2. android 焦点的作用,Android中的视图焦点Focus的详细介绍
  3. Linux Shell脚本攻略学习总结:三
  4. python – IOError:[Errno 28] pip install 设备上没有空间
  5. python语言中的数据类型之字典
  6. DQL——数据查询语言
  7. 视觉测量为什么要考虑畸变
  8. 分页选择器v-selectpage的介绍
  9. android使用遥控器模拟鼠标拖拽操作
  10. 通过DMA方式进行连续发送
  11. 计算机创新创业计划2000字,创新创业论文2000字
  12. 【毕设教程】OLED屏幕介绍与使用
  13. android壁纸设置,android设置壁纸 的方法
  14. 通过命令行操作iOS模拟器
  15. react native 出现程序包com.facebook.react不存在
  16. CSS——CSS基础(一篇就够用)
  17. Java开发基础面试题,北大青鸟java培训多久
  18. 嵌入式基础测试手册——基于NXP iMX6ULL开发板(3)
  19. linux系统下文件夹没有权限
  20. 大数据平台作业调度系统详解-理论篇

热门文章

  1. android oneshot自动播放bug,移动端常见bug汇总001
  2. html盒子模型页面居中,【静态页面架构】CSS之盒子模型
  3. python中dic_python之dic {字典}(重要指数*****)
  4. 上传 mp4 格式判断_视频如何转换成通用的MP4格式?按下这个键,10秒就能搞定...
  5. 网页无法调用java9_JAVA 9 (内部类,异常,包)
  6. python 教学_「Python基础」一次就装好Python手把手装到好
  7. python matplotlib 绘制曲线图,柱状图
  8. linux用户和用户组
  9. (转)JVM监控工具介绍
  10. Albert launcher安装与使用