Skip to content

Instantly share code, notes, and snippets.

@baweaver
Created December 9, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baweaver/6c8e838a40dd3de5e16a128f0bef0d6d to your computer and use it in GitHub Desktop.
Save baweaver/6c8e838a40dd3de5e16a128f0bef0d6d to your computer and use it in GitHub Desktop.
Why does Ruby break on this?
class Foo
attr_accessor :bar
def initialize
@bar = 99
end
def baz
puts bar
bar += 1
end
end
a = Foo.new
puts a.bar
puts a.baz
# OUT:
# ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
# 99
# 99
# undefined method `+' for nil:NilClass
# (repl):11:in `baz'
# (repl):17:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment