lib/under_os/events.rb in under-os-1.2.1 vs lib/under_os/events.rb in under-os-1.3.0

- old
+ new

@@ -17,23 +17,21 @@ module Listeners extend self def list(model, event=nil) - @listeners ||= {} - @listeners[model] ||= {} - @listeners[model][event.to_sym] ||= [] if event + @listeners ||= Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = []} } event ? @listeners[model][event.to_sym] : @listeners[model] end def add(model, event, *args, block) - list(model, event.to_sym) << [block, *args] + list(model, event) << [block, *args] model end def all(model, event) - list(model, event.to_sym) + list(model, event) end def remove(model, event) list(model).delete event.to_sym model @@ -42,10 +40,12 @@ def kick(model, event, params) event = Event.new(event, params) unless event.is_a?(Event) all(model, event.name).each do |block, method_name, *args| if !block && method_name - block = Proc.new{ __send__(method_name, *args) } + block = Proc.new{ |e| + a = method(method_name).arity == 0 ? [] : [e]; + __send__(method_name, *a) } context = model elsif block && method_name # <- considering it's a context reference context = method_name else context = nil