Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access class variable after cd'ing into instance #2069

kisp opened this issue Jul 19, 2019 · 1 comment


Copy link

commented Jul 19, 2019

I create a new class in pry:

class U
  @@name = 123

Now, when I cd into an instance of U by doing cd, I get a NameError when trying to access @@name.

This is the full transcript:

user@my-test-droplet:~$ pry --version
Pry version 0.12.2 on Ruby 2.5.5
user@my-test-droplet:~$ pry 
[1] pry(main)> class U
[1] pry(main)*   @@name = 123
[1] pry(main)* end  
=> 123
[2] pry(main)> cd
[3] pry(#<U>):1> @@name
NameError: uninitialized class variable @@name in Object
from (pry):4:in `__pry__'
[4] pry(#<U>):1> 

This comment has been minimized.

Copy link

commented Aug 29, 2019

I can duplicate this issue.

To access the class variable, I use self.class.class_variable_get '@@name' from within the object.

However, I would not recommend the use of class variables in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.