Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2015 00:19
Show Gist options
  • Save anonymous/7dbc41b555dfce63585b to your computer and use it in GitHub Desktop.
Save anonymous/7dbc41b555dfce63585b to your computer and use it in GitHub Desktop.
ruby inheritance questions
## 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