Created
June 23, 2014 23:40
-
-
Save eeeschwartz/38bbc6b75859961ee30a to your computer and use it in GitHub Desktop.
attr_accessor issue
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 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