数组前的Ruby *运算符 [英] Ruby * operator before array

查看:87
本文介绍了数组前的Ruby *运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
了解范围和数组中的红宝石摔得痛

Possible Duplicate:
Understanding ruby splat in ranges and arrays

有人可以告诉我以下代码中的*是什么吗?

could anyone tell me what the * does in the following piece of code?

line = "name=yabbi;language=ruby;"
Hash[*line.split(/=|;/)]

谢谢.

推荐答案

*是splat运算符.它用于将数组拆分为参数列表.

* is the splat operator. It is used to split an array into a list of arguments.

line.split(/=|;/)返回一个数组.要创建哈希,必须将数组的每个元素作为单独的参数传递.

line.split(/=|;/) returns an array. To create a Hash, each element of the array must be passed as an individual parameter.

这篇关于数组前的Ruby *运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆