Class Object

  1. lib/cosell/monkey.rb
Parent: Object

Cosell is intended to be way for objects to communicate throughout the Object graph. It is supposed to be pervasive. As such, it has a few top-level methods that all objects inherit.

Methods

public class

  1. as_announcement

public instance

  1. as_announcement
  2. as_announcement_trace

Public class methods

as_announcement ()

When a class is used as an announcment, an empty new instance is created using allocate. Will raise an exception for those rare classes that cannot allocate a new instance.

[show source]
# File lib/cosell/monkey.rb, line 23
  def self.as_announcement
    new_inst = self.allocate rescue nil
    raise "Cannot create an announcement out of #{self}. Please implement 'as_announcement' as a class method of #{self}." if new_inst.nil?
    new_inst
  end

Public instance methods

as_announcement ()

When an object (or class) is announced, :as_announcement is called, the result of which becomes the announcement. By default just returns self, but can be overridden if appropriate. By default, simply return self.

[show source]
# File lib/cosell/monkey.rb, line 11
  def as_announcement
    return self
  end
as_announcement_trace ()

When cosell is configured to “spy!”, the result of announement.as_announcement_trace is what is sent to the spy log. By default just calls ‘to_s’.

[show source]
# File lib/cosell/monkey.rb, line 17
  def as_announcement_trace
    self.to_s rescue "(Warning: could not create announcement trace)"
  end