所以我有一个由collect构建的数组。
@a = Relation.where(part: "v04")
@relations = @a.collect {|x| x.car}
建立…
=>[“f03”,“f04”]
@a = Relation.where(part: "v03")
@relations = @a.collect {|x| x.car}
建立…
=>[“f01”,“f03”]
我想要的是附加collect,以便可以从v03和v04构建一个数组,使其看起来像这样。
=>[“f03”,“f04”,“f01”,“f03”]
然后只保留唯一的值,使其看起来像这样。
=>[“f03”,“f04”,“f01”]
取出f03,因为它被列了两次。
最佳答案
["f03", "f04"] | ["f01", "f03"] #=> ["f03", "f04", "f01"]
car1 = ["f03", "f04"]
car2 = ["f01", "f03"]
car1 | car2 #=> ["f03", "f04", "f01"]