【问题标题】:Get the number of variables in a splat ruby获取 splat ruby​​ 中的变量数
【发布时间】:2014-07-29 01:40:46
【问题描述】:

在调用方法时如何计算作为 splat 参数传递的值的数量?

def splat_demo(*var)
   #code to find out no of values in the splat variable here
end

【问题讨论】:

    标签: ruby splat


    【解决方案1】:

    您会得到一个数组,因此只需运行 var.size 即可获取传入的值的数量。

    【讨论】:

    • 不知道我可以将它用作数组。谢谢!
    • 您不会“将其用作数组”。它一个Array
    猜你喜欢
    • 2017-08-06
    • 2017-04-06
    • 2015-02-23
    • 2012-05-26
    • 2012-09-15
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多