Project

microevent

0.01
Low commit activity in last 3 years
No release in over a year
MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by MicroEvent.js and implemented in less than 20 lines of Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

MicroEvent.rb [version] [CI]

MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by MicroEvent.js, implemented in less than 20 lines of Ruby.

Setup

Add to your Gemfile

gem 'microevent'

or copy the source file into your project.

How to Use It

Suppose you got a class Klass, and you wish it to support the observer partern, do

class Klass
  include MicroEvent
end

That's it. Now all instances of this class can #bind, #unbind and trigger:

fn = proc{ puts "Go" }
object = Klass.new
object.bind :slot, &fn
object.trigger :slot # => Go

You could also use it on class/singleton level:

class Klass
  extend MicroEvent
end

Klass.bind :slot do
  puts "Go"
end

Klass.trigger :slot # => Go

You will find more examples in the tests.

Alternative Variants

Projects Using MicroEvent.rb

MIT License

Ruby version by Jan Lelis. Inspired by MicroEvent.js by Jerome Etienne.