"Its Me" <itsme213 / hotmail.com> schrieb im Newsbeitrag
news:VLzec.19317$jR6.10718 / fe2.texas.rr.com...
> CONTEXT:
> I am working on some code for dynamic binding in Ruby.
>     binding (what_to_bind_and_to_what) {
>         # all code here (nested calls included) sees bindings above
>     }
>     # bindings revert here to previous values
>     # code here sees bindings that existed prior to the binding(...)
above.
>
> However, instead of the usual practice of binding a variable:
>     binding (:var, value) {
>         # all code here (nested calls included) sees :var as bound to
value
>     }
>
> I want to bind an attribute of an object
>     binding (object, accessor, value) {
>         # all code here (nested calls included) sees object.accessor ==
> value
>     }
>
> Reasoning: Ruby is all objects. References to most (all?) non-local
> variables should correspond to attribute access on some object, if you
treat
> things like hash[key] as sugar for hash.get_attr(key).
>
> QUESTION:
> Do global variables in Ruby correspond to attributes on some object? Is
> there a way to get hold of that object and find or define accessors for
> those variables? Most specifically, if that object is referred to as
> _globals_, is there a way to define:
>     def _globals_.get_attr (global_symbol)
> and
>     def _globals_.set_attr (global_symbol, value)
>
> Thanks!

Hm, there is Kernel.global_variables() but no getter or setter, which you
could override.  Do I miss something here?

Regards

    robert