Created
September 23, 2016 20:44
-
-
Save hlrd93/a8889457a7e080226175dbe62ac8a34a to your computer and use it in GitHub Desktop.
learning_inheritance
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 Auto | |
attr_accessor :nValves, :wheels | |
attr_reader :model | |
attr_writer :model | |
#Methods are public by default | |
def self.motorValves | |
"It has #{ nValves } Valves"; | |
end | |
def self.nValves | |
@nValves | |
end | |
def self.description | |
"Yor Vette has a #{ nValves } Valves and it has #{ wheels } wheels. Congrats is a #{ model } !" | |
end | |
end | |
class V6 < Auto | |
#constructor | |
def initialize(nValves, wheels, model) | |
@nValves = nValves | |
@wheels = wheels | |
@model = model | |
end | |
end | |
corvette = V6.new(16, 4, 'C6') | |
# corvette.nValves = 16 | |
# corvette.model = 'C6' | |
corvette.description | |
#puts corvette.model | |
#puts corvette.nValves | |
#puts corvette.motorValves | |
#puts corvette.description |
GusGA
commented
Sep 23, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment