title: How to consume data from a pub/sub pattern in ruby?
body: <p>I am new to Ruby and have been following a couple of tutorials to learn more about it.</p>
  <p>Here's the baseline code. I have a Publisher and a class, Checkout, that <code>includes</code> this Publisher.</p>
  <pre><code>module MyPublisher
      def subscribe(subscribers)
        @subscribers += subscribers
      end
    
      def publish(event, *payload)
        @subscribers ||= []
        @subscribers.each do |subscriber|
          subscriber.public_send(event.to_sym, *payload) if subscriber.respond_to?(event)
        end
      end
  end
  
  class Checkout
      include MyPublisher
  end 
  
  checkout = Checkout.new
  items = []
  
  checkout.subscribe &quot;event-item-added&quot; do |data|
      # How can I get here inside this listener? So that &quot;item &lt;&lt; data&quot; is executed?
      puts &quot;checkout received an item!&quot;
      items &lt;&lt; data
  end
  
  queue.publish &quot;event-item-added&quot;, 52
  queue.publish &quot;event-item-added&quot;, 90
  queue.publish &quot;event-item-added&quot;, 16
  </code></pre>
  <p>My question is: how to get the data that is published inside the <code>...do |data|</code> block/listener? (I also put a comment to show where I am talking about).</p>