Possible Duplicate:
How to count duplicates in Ruby Arrays
Ruby: Compare 2 arrays for matches, and count the number of match instances
I am starting to using ruby language. Suppose I have two arrays:
a=["A", "B", "C", "D"]
b=["C", "A", "X", "Y", "F"]
I would like to count the number of duplicated elements of the two arrays. To achieve this, the idea I came up with is like following:
nr_of_duplicates = (a- (a - b)).size
Is there a better way to achieve this?