[REBOL] Re: Embedded objects.
From: joel:neely:fedex at: 12-Mar-2003 18:02
Hi, Terry,
Bob needs an attribute to keep up with his pet (or pets).
See below.
Terry Brownell wrote:
> How can I embed BobsDog into Bob so I can...
>
The simplest way is:
Bob: make object! [
name: "Bob"
dog: make object! [
name: "Rex"
]
]
after which
>> Bob/dog/name
== "Rex"
A more general solution is to let Bob have multiple pets:
Bob: make object! [
name: "Bob"
pets: []
]
Then you can let Bob adopt as many pets as he likes -- either
pets that are referenced by REBOL words:
BobsDog: make object! [name: "Rex"]
append Bob/pets BobsDog
which allows...
>> Bob/pets/1/name
== "Rex"
0r pets that are only known because they belong to Bob!
append Bob/pets make object! [
species: "cat"
name: "Tiger"
]
append Bob/pets make object! [
species: "hamster"
name: "Throckmorton"
]
which allows...
>> foreach pet Bob/pets [print pet/name]
Rex
Tiger
Throckmorton
>>
HTH!
-jn-
--
----------------------------------------------------------------------
Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446
Counting lines of code is to software development as
counting bricks is to urban development.