Skip to content

Instantly share code, notes, and snippets.

@eeeschwartz
Created June 23, 2014 23:40
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 eeeschwartz/38bbc6b75859961ee30a to your computer and use it in GitHub Desktop.
Save eeeschwartz/38bbc6b75859961ee30a to your computer and use it in GitHub Desktop.
attr_accessor issue
class AnyOldClass
attr_accessor :array_attr
def initialize
self.array_attr = []
this_is_fine
self.array_attr = []
this_also_fine
self.array_attr = []
this_throws_exception
end
def this_is_fine
array_attr << 'foo'
end
def this_also_fine
self.array_attr += ['foo']
end
def this_throws_exception
# undefined method `+' for nil:NilClass (NoMethodError)
array_attr += ['foo']
end
end
AnyOldClass.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment