开发者

Pulling from two arrays a non-matching object

I have two arrays. If an object in one array has no matching email attribute in the other, I want 开发者_如何学Goto build an array out of all those objects..

My attempts at attacking the dragon :

CardReferral.all.map(&:email) - CardSignup.all.map(&:email)

That almost does what I need! Unfortunately, it only supplies an email in an array. And I want the whole object.


t = CardSignup.all.map(&:email)
result = CardReferral.all.reject { |i| t.include? i.email }


Simplified example:

a = [:x, :y, :z]
b = [:a, :y, :b]
a.select { |e| ! b.include? e }
=> [:x, :z]

So I guess in your case it goes something like:

CardReferral.all.select { |e| ! CardSignup.all.include? e.email }

Or, incorporating feedback :-) ...

t = CardSignup.all
CardReferral.all.reject { |e| t.include? e.email }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜