Skip to content

Instantly share code, notes, and snippets.

@tarcieri
Created November 2, 2011 02:13
Show Gist options
  • Save tarcieri/1332669 to your computer and use it in GitHub Desktop.
Save tarcieri/1332669 to your computer and use it in GitHub Desktop.
An example of circular calls in Celluloid
require 'rubygems'
require 'celluloid'
class Charlie
include Celluloid
def initialize(friend)
@nemesis = friend
end
def name; self.class.to_s; end
def ask_whats_up
puts "Charlie asks #{@nemesis.name} what's up"
@nemesis.whats_up? current_actor
end
def whats_up?
what_is_up = "not much"
puts "Charlie's view of what's up is: #{what_is_up}"
what_is_up
end
end
class Ashton
include Celluloid
def name; self.class.to_s; end
def whats_up?(caller)
puts "#{name} gets confused by the question and asks #{caller.name} the same question first!"
callers_response = caller.whats_up?
puts "Now Ashton responds with the same answer. Cool story bro!"
"Same here, #{callers_response} too!"
end
end
ashton = Ashton.new
charlie = Charlie.new ashton
response = charlie.ask_whats_up
puts "Ashton responded: #{response}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment