Ruby's 文档将方法签名显示为:
start_with?([prefixes]+) → true or false
对我来说这看起来像一个数组,但事实并非如此。您可以传递单个字符串或各种字符串作为参数,如下所示:
"hello".start_with?("heaven", "hell") #=> true
如何将数组作为参数列表传递?以下不起作用:
"hello".start_with?(["heaven", "hell"])
括号是文档约定optional所以括号里
start_with?([prefixes]+) → true or false
只是说你可以打电话start_with?
零个或多个prefixes
。这是文档中的常见约定,您会看到它jQuery文档,Backbone文档,MDN JavaScript文档,以及几乎所有其他软件文档。
如果您有一组要使用的前缀start_with?
,然后你可以通过 splat 数组来取消数组的排列:
a = %w[heaven hell]
'hello'.start_with?(*a) # true
a = %w[where is]
'pancakes house?'.start_with?(*a) # false
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)