Object
The root of the class hierarchy. Every class in Maggie ultimately inherits from Object. Provides identity comparison, nil testing, class access, copying, error handling, and a default printString.
3 yourself >>> 3
nil isNil >>> true
3 isNil >>> false
3 notNil >>> true
Class Methods
primitives
Return an array of all classes in the system.
Create a new instance of this class.
Instance Methods
primitives
Return a hash value for the receiver.
If the receiver is nil, evaluate block; otherwise return self.
Evaluate nilBlock if nil, notNilBlock with self otherwise.
If the receiver is not nil, evaluate block with self; otherwise return nil.
Send a message with the given selector to the receiver.
Send a one-argument message to the receiver.
Add a dependent to the receiver's notification list.
Return an Array of the receiver's dependents.
Remove all dependents from the receiver.
Remove a dependent from the receiver's notification list.
uncategorized
Return true if the receiver and other are equal. The default
implementation delegates to identity (==). Subclasses may
override this to provide value equality.
3 = 3 >>> true
3 = 4 >>> false
'hello' = 'hello' >>> true
Return true if the receiver and other are the exact same object
(identity comparison). Two objects that are == always have the
same identity; value equality uses = instead.
3 == 3 >>> true
3 == 4 >>> false
nil == nil >>> true
Register anObject as a dependent of the receiver. When the receiver
sends changed or changed:, anObject will receive update: with
the change aspect. Returns the dependent.
model := Object new. dep := Object new.
model addDependent: dep.
model dependents size >>> 1
Project this object's instance variables into a CUE value. Returns a CueValue whose fields are the ivar names with their current values. Scalars (numbers, strings, booleans) project as CUE scalars. Objects with named ivars project as CUE structs.
42 asCueValue kind >>> 'int'
'hello' asCueValue kind >>> 'string'
Notify all dependents that the receiver has changed, with nil as the aspect.
Notify all dependents that the receiver has changed, passing
anAspect (typically a symbol) to each dependent's update: method.
model := Object new. dep := Object new.
model addDependent: dep.
model dependents size >>> 1
Return the class of the receiver as a first-class class value.
3 class name >>> #SmallInteger
true class name >>> #True
nil class name >>> #UndefinedObject
Return an Array of the receiver's dependents. Returns an empty Array if there are no dependents.
Object new dependents size >>> 0
Called by the VM when a message is sent to an object that does not understand it. Signals an error with the unrecognized selector name.
"Typically not called directly -- triggered by the VM"
3 frobnicate "=> error: Message not understood: frobnicate"
Signal an error with the given message string.
self error: 'something went wrong'
Return true if the receiver is an instance of aClass or one of its subclasses. Uses class identity comparison via the primitive.
3 isKindOf: SmallInteger
Return false. Object is not nil; only UndefinedObject (the class of nil) overrides this to return true.
3 isNil >>> false
'hello' isNil >>> false
nil isNil >>> true
Return false. Used internally by the compiler to test AST node types.
Return false. Used internally by the compiler to test AST node types.
Return true if the receiver is not nil.
3 notNil >>> true
nil notNil >>> false
Return a human-readable representation.
Remove all dependents from the receiver. Use this when an object is being discarded to avoid stale references.
Remove anObject from the receiver's dependents list. Returns the dependent. No error if anObject was not a dependent.
model := Object new. dep := Object new.
model addDependent: dep.
model removeDependent: dep.
model dependents size >>> 0
Return true if the receiver's class (or any superclass) implements the given selector.
3 respondsTo: #printString >>> true
3 respondsTo: #frobnicate >>> false
Return a shallow copy of the receiver. Instance variables are shared (not deeply copied) between the original and the copy.
| original <Array> copy <Array> |
original := Array new: 3.
copy := original shallowCopy.
copy == original "false -- different object"
Called when a dependent object receives a change notification. Override this in subclasses to respond to model changes. The default implementation does nothing.
Return the receiver. Useful at the end of a cascade to yield the original object rather than the last message result.
3 yourself >>> 3
'hello' yourself >>> 'hello'
Return true if the receiver and other are NOT equal.
This is the negation of =.
3 ~= 4 >>> true
3 ~= 3 >>> false
Return true if the receiver and other are NOT the same object.
This is the negation of ==.
3 ~~ 4 >>> true
3 ~~ 3 >>> false