S
Sean O'Dell
I'm thinking, why do we have globals at all? I wonder if it would be
possible to just corral all the "global" stuff (methods, variables,
etc.) and just assign all that to a top-level object instance and use
that object as the default "global context?"
I'm thinking: no fixed global context at all. Just an object instance
that acts as the global context.
By default, you could "mixin" the Kernel module and that would take care
of most the backwards compatibility issues, eh? If not, hopefully you
could mixin other modules to finish the job.
One advantage I'm thinking of is that you could re-assign the global
context to be any object instance, and all global-style references
($variables, ::methods()), would then refer to the new object.
So if you had:
class NewGlobal
include Kernel
def initialize
@stdout = File:pen("capture.txt",
File::RDWR|File::TRUNC|File::CREAT)
end
end
.... in one call, you could print to the console:
print("this goes to the screen\n)
.... then you could switch things up:
Global:ush(NewGlobal.new)
print("this gets captured\n)
.... then return to the previous context:
Global:op
Kind of a nutty idea, maybe?
Sean O'Dell
possible to just corral all the "global" stuff (methods, variables,
etc.) and just assign all that to a top-level object instance and use
that object as the default "global context?"
I'm thinking: no fixed global context at all. Just an object instance
that acts as the global context.
By default, you could "mixin" the Kernel module and that would take care
of most the backwards compatibility issues, eh? If not, hopefully you
could mixin other modules to finish the job.
One advantage I'm thinking of is that you could re-assign the global
context to be any object instance, and all global-style references
($variables, ::methods()), would then refer to the new object.
So if you had:
class NewGlobal
include Kernel
def initialize
@stdout = File:pen("capture.txt",
File::RDWR|File::TRUNC|File::CREAT)
end
end
.... in one call, you could print to the console:
print("this goes to the screen\n)
.... then you could switch things up:
Global:ush(NewGlobal.new)
print("this gets captured\n)
.... then return to the previous context:
Global:op
Kind of a nutty idea, maybe?
Sean O'Dell