lib/nanoc/base/notification_center.rb in nanoc-3.7.4 vs lib/nanoc/base/notification_center.rb in nanoc-3.7.5
- old
+ new
@@ -1,20 +1,17 @@
# encoding: utf-8
module Nanoc
-
# Provides a way to send notifications between objects. It allows blocks
# associated with a certain notification name to be registered; these blocks
# will be called when the notification with the given name is posted.
#
# It is a slightly different implementation of the Observer pattern; the
# table of subscribers is not stored in the observable object itself, but in
# the notification center.
class NotificationCenter
-
class << self
-
# Adds the given block to the list of blocks that should be called when
# the notification with the given name is received.
#
# @param [String, Symbol] name The name of the notification that will
# cause the given block to be called.
@@ -29,11 +26,11 @@
# @return [void]
def on(name, id = nil, &block)
initialize_if_necessary(name)
# Add observer
- @notifications[name] << { :id => id, :block => block }
+ @notifications[name] << { id: id, block: block }
end
# Posts a notification with the given name and the given arguments.
#
# @param [String, Symbol] name The name of the notification that should
@@ -74,11 +71,8 @@
def initialize_if_necessary(name)
@notifications ||= {} # name => observers dictionary
@notifications[name] ||= [] # list of observers
end
-
end
-
end
-
end