Identify unique blocks

Viewed 81

I have an array to which I keep adding blocks of code at different points of time. When a particular event occurs, an iterator iterates through this array and yields the blocks one after the other.

Many of these blocks are the same and I want to avoid executing duplicate blocks.

This is sample code:

    @after_event_hooks = []

    def add_after_event_hook(&block)
      @after_event_hooks << block
    end

Something like @after_event_hooks.uniq or @after_event_hooks |= block don't work.

Is there a way to compare blocks or check their uniqueness?

3 Answers
Related