Add a class variable with a mixin

Is it easily possible to add a class variable to a class via a Mixin?
I’m running into insane problems. Can I access a Class’s class
variables at all(outside of an instance), or are they otherwise private?

Actualy, I can do that. I just need to modify it externally afterwards
by name.

2010/1/28 Gene S. [email protected]:

Actualy, I can do that. I just need to modify it externally afterwards
by name.

What exactly are you trying to do? Here’s one way:

module Foo
attr_accessor :bar
end

String.extend Foo

irb(main):009:0> String.bar = “nonsense”
=> “nonsense”
irb(main):010:0> String.bar
=> “nonsense”
irb(main):011:0>

Kind regards

robert

2010/1/28 Robert K. [email protected]:

String.extend Foo

irb(main):009:0> String.bar = “nonsense”
=> “nonsense”
irb(main):010:0> String.bar
=> “nonsense”
irb(main):011:0>

PS: this is not a class variable in the “classical” sense, e.g. a
variable starting with “@@” (e.g. @@bar). It’s an instance variable
of the class.

Kind regards

robert