Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/cosell/monkey.rb
Overview
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.
Class Method Summary collapse
-
.as_announcement ⇒ Object
When a class is used as an announcment, an empty new instance is created using #allocate.
Instance Method Summary collapse
-
#as_announcement ⇒ Object
When an object (or class) is announced, :as_announcement is called, the result of which becomes the announcement.
-
#as_announcement_trace ⇒ Object
When cosell is configured to “spy!”, the result of announement.as_announcement_trace is what is sent to the spy log.
Class Method Details
.as_announcement ⇒ Object
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.
23 24 25 26 27 |
# 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 |
Instance Method Details
#as_announcement ⇒ Object
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.
11 12 13 |
# File 'lib/cosell/monkey.rb', line 11 def as_announcement return self end |
#as_announcement_trace ⇒ Object
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’.
17 18 19 |
# File 'lib/cosell/monkey.rb', line 17 def as_announcement_trace self.to_s rescue "(Warning: could not create announcement trace)" end |