This is what I’m trying to do:
class Foo; end
Foo.class_exec do
class_variable_set(:@@x, 42)
def get
@@x
end
end
puts Foo.new.get
I’m getting (Ruby 3.2.1):
$ ruby a.rb
a.rb:6:in `get': class variable access from toplevel (RuntimeError)
from a.rb:10:in `<main>'
How can I read this @@x
, which I just set?