Skip to content

Instantly share code, notes, and snippets.

@hlrd93
Created September 23, 2016 20:44
Show Gist options
  • Save hlrd93/a8889457a7e080226175dbe62ac8a34a to your computer and use it in GitHub Desktop.
Save hlrd93/a8889457a7e080226175dbe62ac8a34a to your computer and use it in GitHub Desktop.
learning_inheritance
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
Copy link

GusGA commented Sep 23, 2016

class Auto
   def motorValves
     "It has #{ nValves } Valves";
  end

  def nValves
     @nValves
  end

  def wheels
    @wheels
  end

  def description
    "Yor Vette has a #{ nValves } Valves and it has #{ wheels } wheels. Congrats is a #{ model } !"
  end
end

class V6 < Auto
  def initialize(nValves, wheels, model)
      @nValves = nValves
      @wheels = wheels
      @model = model
    end
end

corvette = V6.new(16, 4, 'C6')

# Esto debería funcionar

puts corvette.nValves
puts corvette.motorValves
puts corvette.description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment