Sha256: fa7f24fc0d7a8f4ac234c38a54e38d67c13ab0c2cc5f1003bca7f9b6fc5691e9
Contents?: true
Size: 833 Bytes
Versions: 13
Compression:
Stored size: 833 Bytes
Contents
# You can define arbitrary events on objects that include this module # It serves as storage for code to be executed later (when fire is # called) # For example: # class Cursor < Lotu::Actor # def initialize # on(:someone_clicked) do # puts 'Someone clicked me!' # end # end # end # # After that you will be able to call #fire(:someone_clicked) from any # instance of class Cursor. # If you pair this with input handling, you will get a nice event # system. Check out the Cursor class to see it in action. module Lotu module Eventful def self.extended(instance) instance.init_behavior end def init_behavior @events = {} end def on(event, &blk) @events[event] = blk end def fire(event, *args) @events[event].call(*args) if @events[event] end end end
Version data entries
13 entries across 13 versions & 1 rubygems