RosettaCodeData/Task/Dynamic-variable-names/Sidef/dynamic-variable-names.sidef
2016-12-05 23:44:36 +01:00

10 lines
308 B
Text

var name = read("Enter a variable name: ", String); # type in 'foo'
class DynamicVar(name, value) {
method init {
DynamicVar.def_method(name, ->(_) { value })
}
}
var v = DynamicVar(name, 42); # creates a dynamic variable
say v.foo; # retrieves the value