Module: Celluloid::ClassMethods

Defined in:
lib/celluloid.rb

Overview

Class methods added to classes which include Celluloid

Instance Method Summary collapse

Instance Method Details

#===(other) ⇒ Object



239
240
241
# File 'lib/celluloid.rb', line 239

def ===(other)
  other.is_a? self
end

#actor_optionsObject

Configuration options for Actor#new



219
220
221
222
223
224
225
226
227
# File 'lib/celluloid.rb', line 219

def actor_options
  {
    actor_system: actor_system,
    mailbox_class: mailbox_class,
    mailbox_size: mailbox_size,
    task_class: task_class,
    exclusive: exclusive_actor,
  }
end

#actor_systemObject



214
215
216
# File 'lib/celluloid.rb', line 214

def actor_system
  Celluloid.actor_system
end

#behavior_optionsObject



229
230
231
232
233
234
235
236
237
# File 'lib/celluloid.rb', line 229

def behavior_options
  {
    proxy_class: proxy_class,
    exclusive_methods: exclusive_methods,
    exit_handler_name: exit_handler_name,
    finalizer: finalizer,
    receiver_block_executions: execute_block_on_receiver,
  }
end

#new(*args, &block) ⇒ Object Also known as: spawn



191
192
193
194
195
# File 'lib/celluloid.rb', line 191

def new(*args, &block)
  proxy = Cell.new(allocate, behavior_options, actor_options).proxy
  proxy._send_(:initialize, *args, &block)
  proxy
end

Create a new actor and link to the current one



199
200
201
202
203
204
205
206
# File 'lib/celluloid.rb', line 199

def new_link(*args, &block)
  fail NotActorError, "can't link outside actor context" unless Celluloid.actor?

  proxy = Cell.new(allocate, behavior_options, actor_options).proxy
  Actor.link(proxy)
  proxy._send_(:initialize, *args, &block)
  proxy
end

#run(*args, &block) ⇒ Object

Run an actor in the foreground



210
211
212
# File 'lib/celluloid.rb', line 210

def run(*args, &block)
  Actor.join(new(*args, &block))
end