-
-
Save nathankleyn/5487683 to your computer and use it in GitHub Desktop.
Updating event fire method to fire event on the @piece. This Gist is for https://github.com/nathankleyn/ruby_events/issues/3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# coding: utf-8 | |
# author : Marc Quinton, march 2013, licence : http://fr.wikipedia.org/wiki/WTFPL | |
libdir = 'lib' | |
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) | |
require 'pp' | |
require 'rubygems' | |
# https://github.com/nathankleyn/ruby_events | |
require 'ruby_events' | |
case ARGV[0] | |
when 'simple' | |
events.listen(:bling) do |event_data| | |
puts 'bling event triggered ; event data = ' + event_data | |
end | |
events.fire(:bling, "hello world") | |
when 'classes' | |
class Piece | |
def initialize | |
puts "Piece.initialize" | |
self.events.listen(:move) do |event_data| | |
puts "Piece.moved " + event_data | |
end | |
self.events.fire(:move, 'from Piece') | |
end | |
end | |
class Puzzle | |
def initialize | |
@piece = Piece.new | |
end | |
def move | |
# send ":move" signal any thing object listening to :move signal | |
@piece.events.fire(:move) | |
end | |
end | |
puzzle=Puzzle.new | |
puzzle.move | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment