2012-02-24 53 views
-1

这是我正在处理的脚本的一部分,它肯定会返回并排列数组,但我希望得到的结果是[[:a, :c].to_set,[:b,:c].to_set].to_set而不是[[:c, :b], [:c, :a]]数组返回子集

@potentially_alive = Array.new 
if (self_defended?(s)) 
    @potentially_alive.delete_if { |pa| pa.subset?(s.to_set)} 
    @potentially_alive.push(s.to_set) 
end 

回答

0

如果您目前的结果是 [[:a, :c], [:b, :c]]

,你想将其更改为 [[:a, :c].to_set, [:b, :c].to_set]

您可以到以下(如果@potentially_alive = [[:a, :c], [:b, :c]]):

@potentially_alive.map! { |a| a.to_set }@potentially_alive = @potentially_alive.map { |a| a.to_set }

+0

对不起,这种解决方案将取代哪里 – 2012-02-24 10:01:01