RSPEC4 Hash_Set

class MyHashSet
def initialize
@store = {}
end

def insert(el)
@store[el] = true
end

def include?(el)
return true if @store[el]
false
end

def to_a
@store.keys
end

def delete(el)
@store = @store.delete_if {|k,v| el == k}
end

def union(set2)
@store.merge!(set2)

end

end

  1. MyHashSet set interaction methods #union returns a new set
    Failure/Error: @store.merge!(set2)

    TypeError:
    no implicit conversion of MyHashSet into Hash

    ./lib/05_my_hash_set.rb:54:in `merge!’

    ./lib/05_my_hash_set.rb:54:in `union’

    ./spec/05_my_hash_set_spec.rb:61:in `block (4 levels) in <top (required)>’

  2. MyHashSet set interaction methods #union returns a set containing elements in EITHER set
    Failure/Error: @store.merge!(set2)

    TypeError:
    no implicit conversion of MyHashSet into Hash

I would like to answer your questions, but I need a little more context as to problems that you are having.

The problem i’m having is the union method, it would not merge set2 into set 1 and the error message is “no implicit conversion of MyHashSet into Hash”
I tried to print set1 and set 2 separately and they are both hash instance.
def union(set2)
@store.merge!(set2)

end

If you look carefully at the specs what’s being passed into the union method isn’t a hash, but an instance of
a MyHashSet object. So, therefore, the compiler isn’t able to merge the 2 sets because they both aren’t hashes. For this to work, you would have to invoke the merge method on the input’s store.