Last active
December 11, 2015 03:48
-
-
Save krisalyssa/4540262 to your computer and use it in GitHub Desktop.
Just how wrong is this? It works, but it feels dirty to call a method on the child class when it's not fully initialized yet.
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 Base | |
def initialize | |
@var = [] | |
init_var | |
end | |
def size_of_var | |
@var.size | |
end | |
end |
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
o = Sub.new | |
o.size_of_var # should return 4 |
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 Sub < Base | |
def init_var | |
@var = %w( some list of elements ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment