Skip to content

Instantly share code, notes, and snippets.

Created August 20, 2017 21:12
Show Gist options
  • Save anonymous/b91f1525ecdbef50da1842ebcbf3975d to your computer and use it in GitHub Desktop.
Save anonymous/b91f1525ecdbef50da1842ebcbf3975d to your computer and use it in GitHub Desktop.
Let's say I have 2 arrays, one is like a pack of cigarrette with different brands of ciggarrettes and second array is like a dozen of different brand of cigarrette packs, and I want to be able to pick a pack of malboro from the second array if someone pick a stick of malboro from first array. I think I can use subscribe method to do it but it lo…
sticks.collect do |stick|
stick.brand
Packs.collect do |pack|
pack.brand == stick.brand
end
end
@havenwood
Copy link

I have:

sticks = {"first" => "malboro", "second" => "kent"}
packs = [{"brand" => "malboro", "type" => "light"}, {"brand" => "kent", "type" => "menthol"}]

I want:

{"first" => {"brand" => "malboro", "type" => "light"}, "second" => {"brand" => "kent", "type" => "menthol"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment