Sha256: 1f7f82d39a73c2200bdbf4fb914d25ee41c0b381b60e3d5ec0d961d34ccb8a82

Contents?: true

Size: 547 Bytes

Versions: 5

Compression:

Stored size: 547 Bytes

Contents

module StreamBot
  module Callbacks    
    def callback(name)
      register_callback(name)
    end

    def callbacks(* names)
      names.each do |name|
        register_callback(name)
      end
    end

    def is_registered?(name)      
      @callbacks.include?(name)
    end

    def register_callback(name)
      class_eval <<-EOF
          def #{name} (*args,&block)
            if block
              @#{name} = block
            elsif @#{name}
              @#{name}.call(*args)
            end
          end
      EOF
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
streambot-0.5.4 lib/streambot/callbacks.rb
streambot-0.5.1 lib/streambot/callbacks.rb
streambot-0.5.0.beta5 lib/streambot/callbacks.rb
streambot-0.5.0.beta4 lib/streambot/callbacks.rb
streambot-0.5.0.beta3 lib/streambot/callbacks.rb