Created
October 10, 2012 12:57
-
-
Save universal/3865473 to your computer and use it in GitHub Desktop.
parent / child super calls
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 Parent | |
attr_accessor :something | |
def print | |
puts self.something | |
end | |
end | |
class Child < Parent | |
def print | |
self.something = "hello" | |
super | |
end | |
end | |
parent = Parent.new | |
parent.something = " world!" | |
child = Child.new | |
child.print | |
parent.print | |
##### | |
ruby test.rb | |
hello | |
world! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment