Sha256: f222e8d7d57492db6076864012446e710df9872137edf193b4c6e7ccfff55284

Contents?: true

Size: 748 Bytes

Versions: 3

Compression:

Stored size: 748 Bytes

Contents

module StreamBot
  module EventHandler

    # register an event with the given name
    def event(name)
      register_event(name)
    end

    # register several events with the given names
    def events(* names)
      names.each do |name|
        event(name)
      end
    end
    
    private
    # the real event registration
    def register_event(name)
      class_eval do
        define_event_method(name);
      end
    end
    
    def define_event_method(name)
      variable =:"@#{name}"
      define_method(name) do
        event = instance_variable_get(variable)
        if event == nil
          event = StreamBot::Event.new(name)
          instance_variable_set(variable, event)
        end
        event
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
streambot-1.0.1 lib/streambot/event_handler.rb
streambot-1.0.0 lib/streambot/event_handler.rb
streambot-1.0.0.rc4 lib/streambot/event_handler.rb