将以下Ruby字符串转换为数组的最佳方法是什么(我使用的是ruby1.9.2/Rails3.0.11)Rails控制台:>Item.first.ingredients=>"[\"Bread,wholewheat,100%,slice\",\"EggSubstitute\",\"new,Eggs,scrambled\"]">Item.first.ingredients.class.name=>"String">Item.first.ingredients.length77期望的输出:>Item.first.ingredients_a["Bread,wholewheat,100%,sl
我有两个数组。第一个数组包含排序顺序。第二个数组包含任意数量的元素。我的属性是保证第二个数组中的所有元素(按值)都在第一个数组中,而且我只处理数字。A=[1,3,4,4,4,5,2,1,1,1,3,3]Order=[3,1,2,4,5]当我对A进行排序时,我希望元素按照Order指定的顺序出现:[3,3,3,1,1,1,1,2,4,4,4,5]请注意,重复是公平的游戏。A中的元素不应更改,只能重新排序。我该怎么做? 最佳答案 >>source=[1,3,4,4,4,5,2,1,1,1,3,3]=>[1,3,4,4,4,5,2,1,1