Created
October 10, 2014 00:50
-
-
Save rafarubert/cdc3025ed585f59dcc5d to your computer and use it in GitHub Desktop.
teste ruby
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 Aluno | |
attr_accessor :matricula, :nome, :notas | |
def media_do_semestre | |
6 | |
end | |
def to_s | |
"#{matricula} - #{nome}" | |
end | |
def inserir_nota nota | |
self.notas ||= [] | |
self.notas << nota | |
end | |
def media | |
notas.inject{|soma, nota_atual| | |
(soma + nota_atual.to_f) / notas.size | |
} | |
end | |
def aprovado? | |
media >= media_do_semestre ? "Sim" : "Não(Estuda macho!!!)" | |
end | |
end | |
class AlunoSegundoSemestre < Aluno | |
def media_do_semestre | |
8 | |
end | |
end | |
deivid = AlunoSegundoSemestre.new | |
deivid.nome = "Deivid" | |
deivid.matricula = 123 | |
deivid.inserir_nota(8) | |
deivid.inserir_nota(6) | |
puts deivid.aprovado? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment