I want to place a variable (value does vary so not a constant) inside a “namespace” and have it accessible from outside.
Searching, I find there’s a few different ways.
cattr_accessor - I can’t yet figure out how to install or use this properly and I’m not using rails. (require fails with “cannot load such file – facets/module/cattr” although facets is installed and just “facets” loads).
getters and setters. These require far too much code to set up, and the setter examples I see seem to only set the = operator, so I can’t use += etc.
What is the least verbose way to let me do something like
I don’t really get the reasoning here (for why it’s so complex) - is ruby actually trying to discourage public static (to use c terminology) variables? is it an oversight or legacy issue? do most people not use namespaces? do people just not use stuff like this often in ruby? or something else?
Would people like, say, being allowed to use the public keyword to modify a variable’s scope?
[SOLVED]: I managed to get mattr_accessor working, just needed a more recent ruby (2.7.1) than the current ubuntu package (2.5) plus the accessor_extender gem.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.