README.rdoc in event_emitter-0.1.0 vs README.rdoc in event_emitter-0.2.0
- old
+ new
@@ -28,40 +28,51 @@
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
see samples https://github.com/shokai/event_emitter/tree/master/samples
== TEST: