Category talk:Wren-trait: Difference between revisions
Content added Content deleted
(→Source code: Removed iteration classes following their transfer to Wren-iterate.) |
(→Source code: Added Const class.) |
||
Line 101: | Line 101: | ||
// Returns the string representation of the current instance. |
// Returns the string representation of the current instance. |
||
toString { _obj.toString } |
toString { _obj.toString } |
||
/* |
|||
Const represents a group of individually named read-only values which are |
|||
stored internally in a map. Any attempt to change such a value is ignored |
|||
though they can be removed from the map. |
|||
*/ |
|||
class Const { |
|||
// Returns the value of 'name' if it is present in the internal map |
|||
// or null otherwise. |
|||
static [name] { (__cmap && __cmap.containsKey(name)) ? __cmap[name] : null } |
|||
// Associates 'value' with 'name' in the internal map. |
|||
// If 'name' is already in the map, the change is ignored. |
|||
static [name]=(value) { |
|||
if (!__cmap) __cmap = {} |
|||
if (!__cmap.containsKey(name)) { |
|||
__cmap[name] = value |
|||
} |
|||
} |
|||
// Removes 'name' and its associated value from the internal map and returns |
|||
// that value. If 'name' was not present in the map, returns null. |
|||
static remove(name) { __cmap.remove(name) } |
|||
// Returns a list of the entries (name/value pairs) in the internal map. |
|||
static entries { __cmap.toList } |
|||
} |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |