Skip to content

Instantly share code, notes, and snippets.

@rafarubert
Created October 10, 2014 00:50
Show Gist options
  • Save rafarubert/cdc3025ed585f59dcc5d to your computer and use it in GitHub Desktop.
Save rafarubert/cdc3025ed585f59dcc5d to your computer and use it in GitHub Desktop.
teste ruby
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