So, my main goal is for each key in hash1, keep only those values that also are present at that identical key in hash2, otherwise remove those values from hash1. I am not concerned with any keys present in Hash2 that are not present in Hash1, btw.

I know arrays can be intersected using "&" and "set", though I have not been able to accomplish this in my script so far.

Your example includes :bravo => [nil], but I think that is an error since nil is not a common element between the :bravo key in hash1 and hash2, so it doesn't make sense. If you want an empty list for keys that are in hash1 and hash2 but have no common elements in their value lists you can remove the third line, which otherwise removes those.

Hi Jorg. Thanks for the help. I am getting an error when I try and run your solution. "intersection.rb:23:in `[]': odd number of arguments for Hash (ArgumentError) from intersection.rb:23"
–
user511038Nov 24 '10 at 19:26

I am able to use your solution now, however it think I need to keep looking at it, as it is not generating a true intersection of the values. Thanks again!!
–
user511038Nov 24 '10 at 19:51

@user511038: Given that your question contained no sample data, no testcases, no example runs, no specification of what you want the code to do and the code you posted doesn't seem to have anything to do with your question (and even if it did, it wouldn't be of any help, since it depends on external files that you didn't post), I tried my best decipher your cryptic description. If there's anything I misinterpreted, let me know and I can fix it.
–
Jörg W MittagNov 24 '10 at 19:59

Jorg, yes, I did post what I wanted the code to do. If I hadn't done so, how would you even make an attempt at writing your code in your answer? Also, posting my code may not be directly relevant to the question at hand, but from what I have seen on these forums, asking a question without even attempting any leg-work yourself is a major violation of forum etiquette. Anyway, as I said above, thank you for your help and I will keep working on it.
–
user511038Nov 24 '10 at 20:32

@user511038: Now that you have provided an actual testcase and I understand what it actually is that you are trying to do, the change was trivial. See the edited solution above.
–
Jörg W MittagNov 24 '10 at 20:45

Additionally, you check the size of h1.keys compared to h2.keys first and then iterate over the smaller one first. It loses a bit of the clarity of the above, but it will perform a lot better for larger hashes with a disparity in sizes.