Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
d = .dynamicvar~new
|
||||
d~foo = 123
|
||||
say d~foo
|
||||
|
||||
d2 = .dynamicvar2~new
|
||||
d~bar = "Fred"
|
||||
say d~bar
|
||||
|
||||
-- a class that allows dynamic variables. Since this is a mixin, this
|
||||
-- capability can be added to any class using multiple inheritance
|
||||
::class dynamicvar MIXINCLASS object
|
||||
::method init
|
||||
expose variables
|
||||
variables = .directory~new
|
||||
|
||||
-- the UNKNOWN method is invoked for all unknown messages. We turn this
|
||||
-- into either an assignment or a retrieval for the desired item
|
||||
::method unknown
|
||||
expose variables
|
||||
use strict arg messageName, arguments
|
||||
|
||||
-- assignment messages end with '=', which tells us what to do
|
||||
if messageName~right(1) == '=' then do
|
||||
variables[messageName~left(messageName~length - 1)] = arguments[1]
|
||||
end
|
||||
else do
|
||||
return variables[messageName]
|
||||
end
|
||||
|
||||
|
||||
-- this class is not a direct subclass of dynamicvar, but mixes in the
|
||||
-- functionality using multiple inheritance
|
||||
::class dynamicvar2 inherit dynamicvar
|
||||
::method init
|
||||
-- mixin init methods are not automatically invoked, so we must
|
||||
-- explicitly invoke this
|
||||
self~init:.dynamicvar
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
d = .dynamicvar~new
|
||||
d~foo = 123
|
||||
say d~foo
|
||||
|
||||
-- a class that allows dynamic variables. Since this is a mixin, this
|
||||
-- capability can be added to any class using multiple inheritance
|
||||
::class dynamicvar MIXINCLASS object
|
||||
::method init
|
||||
expose variables
|
||||
variables = .directory~new
|
||||
|
||||
-- the unknown method will get invoked any time an unknown method is
|
||||
-- used. This UNKNOWN method will add attribute methods for the given
|
||||
-- name that will be available on all subsequent uses.
|
||||
::method unknown
|
||||
expose variables
|
||||
use strict arg messageName, arguments
|
||||
|
||||
-- check for an assignment or fetch, and get the proper
|
||||
-- method name
|
||||
if messageName~right(1) == '=' then do
|
||||
variableName = messageName~left(messageName~length - 1)
|
||||
end
|
||||
else do
|
||||
variableName = messageName
|
||||
end
|
||||
|
||||
-- define a pair of methods to set and retrieve the instance variable. These are
|
||||
-- created at the object scope
|
||||
self~setMethod(variableName, 'expose' variableName'; return' variableName)
|
||||
self~setMethod(variableName'=', 'expose' variableName'; use strict arg value;' variableName '= value' )
|
||||
|
||||
-- reinvoke the original message. This will now go to the dynamically added
|
||||
methods
|
||||
forward to(self) message(messageName) arguments(arguments)
|
||||
Loading…
Add table
Add a link
Reference in a new issue