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.
Public class methods
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.
# 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
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.
# File lib/cosell/monkey.rb, line 11 def as_announcement return self end
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’.
# File lib/cosell/monkey.rb, line 17 def as_announcement_trace self.to_s rescue "(Warning: could not create announcement trace)" end