<commit_before>module RailsEventStore
  module PubSub
    class Broker

      def initialize
        @subscribers = {}
      end

      def add_subscriber(subscriber, event_types)
        raise SubscriberNotExist  if subscriber.nil?
        raise MethodNotDefined    unless subscriber.methods.include? :handle_event
        subscribe(subscriber, [*event_types])
      end

      def notify_subscribers(event)
        [event.event_type, ALL_EVENTS].each do |type|
          notify(event, type)
        end
      end

      private
      attr_reader :subscribers

      def subscribe(subscriber, event_types)
        event_types.each do |type|
          (subscribers[type] ||= []) << subscriber
        end
      end

      def notify(event, event_type)
        if subscribers.key? event_type
          subscribers[event_type].each do |subscriber|
            subscriber.handle_event(event)
          end
        end
      end
    end
  end
end
<commit_msg>elimiate the if by using the hash default value<commit_after>module RailsEventStore
  module PubSub
    class Broker

      def initialize
        @subscribers = Hash.new {|hsh, key| hsh[key] = [] }
      end

      def add_subscriber(subscriber, event_types)
        raise SubscriberNotExist  if subscriber.nil?
        raise MethodNotDefined    unless subscriber.methods.include? :handle_event
        subscribe(subscriber, [*event_types])
      end

      def notify_subscribers(event)
        [event.event_type, ALL_EVENTS].each do |type|
          notify(event, type)
        end
      end

      private
      attr_reader :subscribers

      def subscribe(subscriber, event_types)
        event_types.each do |type|
          subscribers[type] << subscriber
        end
      end

      def notify(event, event_type)
        subscribers[event_type].each do |subscriber|
          subscriber.handle_event(event)
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06799163179916318, 'fraction_numerical': 0.0, 'mean_word_length': 2.215126050420168, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3432663', 'n_tokens_mistral': 570, 'n_tokens_neox': 541, 'n_words': 136}