stevefolder/vendor/bundle/ruby/3.1.0/gems/event_emitter-0.2.6
2022-02-04 18:48:09 -05:00
..
benchmark init 2022-02-04 18:48:09 -05:00
lib init 2022-02-04 18:48:09 -05:00
samples init 2022-02-04 18:48:09 -05:00
test init 2022-02-04 18:48:09 -05:00
.gitignore init 2022-02-04 18:48:09 -05:00
.travis.yml init 2022-02-04 18:48:09 -05:00
event_emitter.gemspec init 2022-02-04 18:48:09 -05:00
Gemfile init 2022-02-04 18:48:09 -05:00
History.txt init 2022-02-04 18:48:09 -05:00
LICENSE.txt init 2022-02-04 18:48:09 -05:00
Rakefile init 2022-02-04 18:48:09 -05:00
README.md init 2022-02-04 18:48:09 -05:00

event_emitter

Build Status

Install

% gem install event_emitter

Requirements

testing on

  • Ruby 1.8.7
  • Ruby 1.9.2
  • Ruby 2.0.0
  • Ruby 2.1.0
  • JRuby

Synopsys

load rubygem

require "rubygems"
require "event_emitter"

include

class User
  include EventEmitter
  attr_accessor :name
end

regist event listener

user = User.new
user.name = "shokai"
user.on :go do |data|
  puts "#{name} go to #{data[:place]}"
end

call event

user.emit :go, {:place => "mountain"}
# => "shokai go to mountain"

regist event using "once"

user.once :eat do |what, where|
  puts "#{name} -> eat #{what} at #{where}"
end

call

user.emit :eat, "BEEF", "zanmai"  # =>  "shokai -> eat BEEF at zanmai"
user.emit :eat, "Ramen", "marutomo"  # => do not call. call only first time.

apply as instance-specific method

class Foo
end

foo = Foo.new
EventEmitter.apply foo

remove event listener

user.remove_listener :go
user.remove_listener event_id

catch all events

user.on :* do |event_name, args|
  puts event_name + " called"
  p args
end

see samples https://github.com/shokai/event_emitter/tree/master/samples

Test

% gem install bundler
% bundle install
% rake test

Benchmark

% rake benchmark

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request