T
Thomas Hafner
Hello,
a startup file to be loaded by RUBYOPT should have minimal side
effects. I guess, this pattern will do it:
class << Object.new
FOO = ... # will not override FOO if defined before
BAR = ... # will introduce BAR intermediately
...
# Use the constants above to do some wanted side effect on an
# object hold by a global variable, e.g. $LOAD_PATH :
$:.unshift(FOO, ...)
end
# no more BAR visible here
Is there a canonical way to achive this kind of hygiene?
Regards
Thomas
a startup file to be loaded by RUBYOPT should have minimal side
effects. I guess, this pattern will do it:
class << Object.new
FOO = ... # will not override FOO if defined before
BAR = ... # will introduce BAR intermediately
...
# Use the constants above to do some wanted side effect on an
# object hold by a global variable, e.g. $LOAD_PATH :
$:.unshift(FOO, ...)
end
# no more BAR visible here
Is there a canonical way to achive this kind of hygiene?
Regards
Thomas