Ruby 参数列表中的单个 splat/星号是什么意思? [英] What does a single splat/asterisk in a Ruby argument list mean?

查看:43
本文介绍了Ruby 参数列表中的单个 splat/星号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天翻阅了 Rails 3 ActiveRecord 源代码,发现 一种方法,其中整个参数列表都是一个星号.

I was poking through the Rails 3 ActiveRecord source code today and found a method where the entire parameter list was a single asterisk.

def save(*)

我找不到对它的作用的很好的描述(尽管我根据我对 splat 参数的了解有一些想法).

I couldn't find a good description of what this does (though I have some ideas based on what I know about splat arguments).

它有什么作用,为什么要使用它?

What does it do, and why would you use it?

推荐答案

这意味着它可以有任意数量的参数(包括零)并丢弃所有这些参数.

It means it can have any number of arguments (including zero) and it discards all those arguments.

这篇关于Ruby 参数列表中的单个 splat/星号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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