-
-
Save net/f13fe33096d3aaa90fac to your computer and use it in GitHub Desktop.
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
# This has issues with inheritance because @@thing isn't idependant to each class | |
class Parent | |
@@thing = [] | |
def self.thing | |
@@thing | |
end | |
end | |
class Child < Parent | |
end | |
Parent.thing << :a | |
Child.thing | |
# => :a | |
# This has issues with inheritance because @thing isn't set for child classes | |
class Parent | |
@thing = [] | |
def self.thing | |
@thing | |
end | |
end | |
class Child < Parent | |
end | |
Parent.thing << :a | |
Child.thing | |
# => nil | |
# This one has no issues with inheritance | |
class Parent | |
def self.thing | |
@thing ||= [] | |
end | |
end | |
class Child << Parent | |
end | |
Parent.thing << :a | |
Child.thing | |
# => [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment