Created
October 4, 2017 12:47
-
-
Save vasilakisfil/7eb19688f3861d9e1b54437c47c60f07 to your computer and use it in GitHub Desktop.
Weird Ruby behavior on private method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foobar | |
def run! | |
self.foobar = 'test' #doesn't fail? | |
hey = self.foobar #bang! fails | |
end | |
private | |
attr_accessor :foobar | |
end | |
Foobar.new.run! | |
#private_foobar.rb:4:in `run!': private method `foobar' called for #<Foobar:0x7fc5956ab780 @foobar="test"> (NoMethodError) | |
# from private_foobar.rb:10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment