Created
June 13, 2015 00:19
-
-
Save anonymous/7dbc41b555dfce63585b to your computer and use it in GitHub Desktop.
ruby inheritance questions
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
## irb -- best way to get this behavior? | |
# >> load 'person.rb' | |
# => true | |
# >> jon = Bastard_Northerner.new('jon', 'stark') | |
# => #<Bastard_Northerner:0x007f07086781b0 @first_name="jon", @last_name="snow"> | |
## person.rb -- is this the right way? | |
class Person | |
attr_accessor :first_name, :last_name | |
def initialize (first_name, last_name) | |
@first_name = first_name | |
self.last_name = last_name | |
end | |
end | |
class Bastard_Northerner < Person | |
# bastard_northerners default to last_name 'snow' | |
def last_name= (input_str = 'snow') | |
@last_name = 'snow' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment