Jump to content

Add a variable to a class instance at runtime: Difference between revisions

m (→‎{{header|REBOL}}: Syntax highlighter defeats REBOL's run from web page semantics. Removed enclosing brackets.)
Line 121:
'''Array:'''
In this example we add a function (which prints out the content of the array) and a new value. While we are not technically adding a "variable", this example is presented to show similar type of functionality.
<lang falcon>vect = [ 'alpha', 'beta', 'gamma' ]
vect = [ 'alpha', 'beta', 'gamma' ]
vect.dump = function ()
for n in [0: self.len()]
Line 129 ⟶ 128:
end
vect += 'delta'
vect.dump()</lang>
</lang>
'''Dictionary:'''
In this example we will add a variable through the use of an object from a bless'ed dictionary. We create a new variable called 'newVar' at runtime and assign a string to it. Additionally we assign an external, to the object, function (sub_func) to the variable 'sub'.
<lang falcon>function sub_func( value )
function sub_func( value )
self['prop'] -= value
return self.prop
Line 148 ⟶ 145:
])
 
dict[ 'newVar' ] = "I'm Rich In Data"</lang>
</lang>
 
=={{header|Io}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.