Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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