brainguy icon indicating copy to clipboard operation
brainguy copied to clipboard

Different input for block shortcut method on()

Open wojtha opened this issue 9 years ago • 0 comments

Hi Avdi,

I was doing some research about this gem and I've found unexpected behavior when using the on shortcut syntax. I've expected full event as the block argument but I got only event explicit arguments (see the exampel below).

If this behavior is intentional what was decision behind it?

require 'brainguy'

class BrainguyWorker
  include Brainguy::Observable

  def call(name)
    emit(:call_success, "Called #{name}")
  end
end

class BrainguyListener
  include Brainguy::Observer

  def on_call_success(event)
    puts "Listener: #{event.inspect}"
  end
end

brain = BrainguyWorker.new
brain.events.attach BrainguyListener.new
listener = proc do |event|
  puts "Proc: #{event.inspect}"
end
brain.on(:call_success) do |event|
  puts "Block: #{event.inspect}"
end

# Output:
# Listener: #<struct Brainguy::Event name=:call_success,... args=["Called Blurb"]>
# Proc: #<struct Brainguy::Event name=:call_success,... args=["Called Blurb"]>
# Block: "Called Blurb"

wojtha avatar Oct 30 '15 18:10 wojtha