REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Objects: Accessing Objects

Pending Revision

This document was written for R2 and has yet to be revised for R3.

Variables within objects are accessed with paths. The path consists of the object name followed by the name of the variable. For example, the following code accesses the variables in the example object:



Here are examples using the bank-account object:

print luke/last-name
print fred/balance

Using a path, the variables of an object can also be modified:

fred/balance: $1000.00
print fred/balance

You can use the in function to access object variables by fetching their words from within their object context:

print in fred 'balance

The balance word returned has the object fred as its context. You can get the value it holds by using get:

print get in fred 'balance

The second argument to the in function is a literal word. This allows you to dynamically change words depending on what is needed:

words: [first-name last-name balance]
foreach word words [print get in fred word]

Each word in the block is used to obtain its value in the object.

The in function can also be used to set object variables.

set in fred 'balance $20.00
print fred/balance

If a word is not defined within an object, the in function returns none! . This is useful for detecting when a variable exists within an object.

if get in fred 'bank [print fred/bank]

  TOC < Back Next > - WIP Wiki Feedback Admin