Arrays 使用数组将多个参数传递给变量参数ruby方法
我现在正在使用一个RubyGem,它接受可变数量的参数(具体来说,它是AXLSXGem) 我正在使用Arrays 使用数组将多个参数传递给变量参数ruby方法,arrays,ruby,axlsx,Arrays,Ruby,Axlsx,我现在正在使用一个RubyGem,它接受可变数量的参数(具体来说,它是AXLSXGem) 我正在使用column\u widths函数,定义为: def column_widths(*widths) widths.each_with_index do |value, index| next if value == nil Axlsx::validate_unsigned_numeric(value) unless value == nil find_or_create
column\u width
s函数,定义为:
def column_widths(*widths)
widths.each_with_index do |value, index|
next if value == nil
Axlsx::validate_unsigned_numeric(value) unless value == nil
find_or_create_column_info(index).width = value
end
end
我有一个需要设置的动态宽度数(因为列的数量不同),所以我尝试创建一个宽度数组并将其传入,但它将数组视为单个参数
如何将数组作为参数列表传入
编辑:
实际误差为:
无效数据[30,13,20,13,20,13,20,13,10,10,10,13,20,10]
对于无效的列宽。必须是[Fixnum,Integer,Float]
您可以在方法定义和方法调用中使用splat。这应该起作用:
column_widths(*array_of_widths)
我认为你做得很好,实际的错误是什么?顺便说一句,问题看起来是一样的。编辑以反映实际的错误,我看了一下,但它没有回答我的问题或解决我的问题Nevermind@Lucio,你是对的-我看到了,但不知怎么的,我跳过了答案而不是最上面的。我的坏朋友,那起作用了-谢谢