什么样的红宝石方法调用的是阵列(X) [英] What kind of ruby method call is Array(x)

查看:101
本文介绍了什么样的红宝石方法调用的是阵列(X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么意思,哪里是语法的Ruby文档:

What is the meaning, and where is the Ruby documentation for the syntax of:

Array(phrases)

我发现这里浏览Rails的来源:

which I found browsing the Rails source here:

# File actionpack/lib/action_view/helpers/text_helper.rb, line 109
...
119:           match = Array(phrases).map { |p| Regexp.escape(p) }.join('|')

我认为Array.new通常会被用来创建一个数组,这样不同的东西必须在这里发生了。顺便说一句,从解决此code的背景下,短语变量可以是一个字符串或字符串数​​组。

I thought that Array.new would normally be used to create an array, so something different must be going on here. BTW from the context around this code, the phrases variable can be either a string or an array of strings.

推荐答案

这是最有可能的内核#阵列方法,看的此处。这比 Array.new 略有不同;它更像是一个演员到一个数组。 (它试图 to_ary to_a

It's most likely the Kernel#Array method, see here. It's slightly different than Array.new; it's more of a cast into an array. (It tries to_ary and to_a.)

这篇关于什么样的红宝石方法调用的是阵列(X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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