I am trying to use the bitwise operator (&) for the arrays in the Ruby on Rails
When I have the simple type arrays
one = ["one", "two", "three"]
two = ["one", "two", "three"]
And have this code
puts (one & two)
I get the output:
one two three
However, when I am having the complex types arrays
list1 = [Someitem.new("1", "item1"),Someitem.new("2", "item2"),Someitem.new("3", "item3"),Someitem.new("4", "item4")]
list2 = [Someitem.new("1", "item1"),Someitem.new("2", "item2"),Someitem.new("3", "item3"),Someitem.new("4", "item4")]
For the class where I do override the to_s method
class Someitem
attr_accessor :item_id, :item_name
def initialize(item_id, item_name)
self.item_id = item_id;
self.item_name= item_name;
end
def to_s
item_name
end
end
And have this code
puts (list1 & list2)
I get nothing in the output
What can I do to get the output for the complex types arrays using the bitwise & operator to find common values within those two lists?