Project

rbevents

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Provides an Event mixin for enabling classes to create events for public and private subscription.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
~> 0.8
~> 3.0
 Project Readme

rbevents

It's like Observable, but better.

Gem Version Code Climate

Example

# Let's define a class with subscribable events
class EventsExample
  include Events # Mix in the magic
  
  # Define an event
  event :activation
  
  # Here, we define a method that fires the event 
  def activate
    # Event.fire sets off the event and collects
    # any return values from subscribed events
    return_values = @activation.fire
    return_values
  end
end

# Let's build an object...
example = EventsExample.new

# ...and then add some subscribers
example.on_activation do
  "Hello"
end
example.on_activation do
  "World!"
end

# Finally, we call a method which alerts the subscribers
example.activate # => ["Hello", "World!"]

Anything else? Check the code.