我有一个这样的命名范围:
named_scope :by_items,lambda |*items| { :joins => :items,:conditions => ["items.id in (?)",items.map(&::id)] }
什么是“*项目”是什么意思?当我用“Item.find(:first,…)”命名时,它可以正常工作.如果我尝试使用一个集合,“Item.find(:all,…)”它失败.
从另一个SO问题,我知道签名应该是:
Order.by_items(item0,item1,...)
所以我的问题真的是,我如何把一个数组变成一个逗号分隔的参数列表?
UPDATE0
从Martin Fowler我学到了:
(Using a “*” in the argument list helps in working with variable arguments in ruby. In the argument list *disks indicates a vararg. I can then refer to all the disks passed in as an array named “disks”. If I call another function with “*disks” the elements of the disks array are passed in as separate arguments.)
UPDATE1
@L_502_1@更多.