Skip to content

Instantly share code, notes, and snippets.

@vasilakisfil
Created October 4, 2017 12:47
Show Gist options
  • Save vasilakisfil/7eb19688f3861d9e1b54437c47c60f07 to your computer and use it in GitHub Desktop.
Save vasilakisfil/7eb19688f3861d9e1b54437c47c60f07 to your computer and use it in GitHub Desktop.
Weird Ruby behavior on private method
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