|
Class: InlineObject
Object
|
+--InlineObject
|
+--InlineObject::InlineObjectPrototype
- Package:
- stx:libbasic
- Category:
- Kernel-Classes
- Version:
- rev:
1.30
date: 2023/09/28 09:57:35
- user: stefan
- file: InlineObject.st directory: libbasic
- module: stx stc-classLibrary: libbasic
WARNING: InlineObjects are an experimental feature.
InlineObjects are written as literals of the form:
#{
fieldName1: value1.
fieldName2: value2.
...
fieldNameN: valueN.
}
For example:
#{
firstName: 'Peter'.
lastName: 'Miller'.
age: 25.
}
The above was an inline literal: all field values must be again literals.
WARNING: the following is currently ONLY experimental,
and may or may not be supported by stc.
Do not use non-literal inline objects at the moment.
However, similar to brace-Arrays, inline objects can also be dynamically created (constructed):
{
date: Date today.
time: Time now.
}
All inlineObjects will be instances of an anonymous subclass of me,
and provide getter protocol for their fields (e.g. firstName, lastName and age in the above example.
Literal InlineObjects are immutable (no setters), whereas constructed are not.
|foo|
foo := { date: Date today. time: Time now }.
foo date:(Date yesterday).
foo
copyrightCOPYRIGHT (c) 2009 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
flushing
-
flushMapOfClasses
-
instance creation
-
slotNames: names values: slotValues
-
return a new inline object given slot names and slot values
Usage example(s):
InlineObject slotNames:#('foo' 'bar' 'baz') values:#(1 2 3)
InlineObject slotNames:#('foo' 'bar' 'baz') values:#(1 2 3) mutable:false
|
-
slotNames: names values: slotValues mutable: mutable
-
return a new inline object given slot names and slot values
Usage example(s):
InlineObject slotNames:#('foo' 'bar' 'baz') values:#(1 2 3)
InlineObject slotNames:#('foo' 'bar') values:#(1 2)
|
-
slotNamesAndValues: namesAndValues
-
return a new inline object given slot names and slot values as alternating elements
in the argument, namesAndValues
Usage example(s):
InlineObject slotNamesAndValues:#('foo' 10 'bar' 20 'baz' 30)
|
-
slotNamesAndValues: namesAndValues mutable: beMutable
-
return a new inline object given slot names and slot values either as alternating elements
in the argument, namesAndValues, or as a dictionary associating values to slotnames
Usage example(s):
InlineObject slotNamesAndValues:#('foo' 10 'bar' 20 'baz' 30)
|
-
slotNamesAndValuesFromDictionary: namesAndValuesDict
-
return a new inline object given slot names and slot values as elements
in the argument, namesAndValuesDict
Usage example(s):
InlineObject slotNamesAndValuesFromDictionary:(Dictionary withKeyValuePairs:#(('foo' 10) ('bar' 20) ('baz' 30)))
|
-
slotNamesAndValuesFromDictionary: namesAndValuesDict mutable: beMutable
-
return a new inline object, given slot names and slot values as elements
in the argument, namesAndValuesDict.
If the dictionary is unordered, slots are created in the sorted key order
Usage example(s):
InlineObject
slotNamesAndValuesFromDictionary:(
Dictionary withKeyValuePairs:#(('foo' 10) ('bar' 20) ('baz' 30))
)
InlineObject
slotNamesAndValuesFromDictionary:(
OrderedDictionary withKeyValuePairs:#( ('bar' 20) ('baz' 30) ('foo' 10) )
)
|
prototype access
-
prototype
-
queries
-
classForSlotNames: slotNames mutable: mutable
-
return either an existing or a new class to represent
an inline object given its slot names
Usage example(s):
|cls1 cls2|
cls1 := self classForSlotNames:#('foo' 'bar' 'baz') mutable:false.
cls2 := self classForSlotNames:#('foo' 'bar' 'baz') mutable:true.
self assert:(self classForSlotNames:#('foo' 'bar' 'baz') mutable:false) == cls1.
self assert:(self classForSlotNames:#('foo' 'bar' 'baz') mutable:true) == cls2.
|
-
isAbstract
-
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.
collection protocol
-
_at: key
-
(comment from inherited method)
this is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx] is parsed.
I.e.
foo[n]
generates
foo _at: n
-
_at: key put: newValue
-
(comment from inherited method)
this is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] := val is parsed.
I.e.
foo[n] := val
generates
foo _at:n put:val
comparing
-
= someObject
-
I conside someObject to be equal, if it has the same slotnames
-
hash
-
I redefine =; so I also have to redefine hash
-
isInlineObject
-
(comment from inherited method)
return true if the receiver is some kind of inline object;
false is returned here - the method is only redefined in InlineObject.
printing & storing
-
displayOn: aStream
-
#{ foo: 1 . bar: 2 } displayString
-
storeOn: aStream
-
#{ foo: 1 . bar: 2 } storeString
Object readFrom:( #{ foo: 1 . bar: 2 } storeString)
InlineObjectClassDescription
InlineObjectPrototype
|