On 26.10.10 23:23, vitick@gmail.com wrote:
Is it possible to have a non-positional argument that is optional and its variable is only set when it is present as the argument to the method. Otherwise, it is ignored, no error. Basically, I want it behave like an option to the method but without specifying any value.
...
Or, it can even be a boolean, set to 1 if it was specified and set to 0 if not. That would be even better, shorter code.
see below for some optional argument handling. i guess you want m2. -gustaf neumann
===================================== Object create myobj { :public method m1 {-test} { puts "m1 test exists [info exists test]" } :public method m2 {-test:switch} { puts "m2 test exists [info exists test] value $test" } :public method m3 {test:optional} { puts "m3 test exists [info exists test]" } }
myobj m1 myobj m1 -test 1 myobj m2 myobj m2 -test myobj m3 myobj m3 1 =====================================
output is
===================================== m1 test exists 0 m1 test exists 1 m2 test exists 1 value 0 m2 test exists 1 value 1 m3 test exists 0 m3 test exists 1 =====================================