Variable or method

Now I know what this error message really means…

NameError: undefined local variable or method `xxx' for main:Object
[1] pry(main)> foo = 7
=> 7
[2] pry(main)> def foo
[2] pry(main)*   5
[2] pry(main)* end
=> :foo
[3] pry(main)> foo
=> 7

equals

shoot in foot

Turns out, the ‘foo’ method is just a shorthand for ‘self.foo’ so it is still accessible, but a little bit hidden:

[4] pry(main)> self.foo
=> 5

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s