Skip to content

Instantly share code, notes, and snippets.

@cpappen
Last active August 29, 2015 14:22
Show Gist options
  • Save cpappen/8b61328e1099dee47bfc to your computer and use it in GitHub Desktop.
Save cpappen/8b61328e1099dee47bfc to your computer and use it in GitHub Desktop.
# http://dojopuzzles.com/problemas/exibe/calculando-estatisticas-simples/
class Valor
def initialize
@numeros = []
end
def adiciona(valor)
@numeros << valor
end
def total
@total = @numeros
puts "Valores: #{@total}"
end
def minimo
@minimo = @numeros.min
puts "Minimo: #{@minimo}"
end
def maximo
@maximo = @numeros.max
puts "Maximo: #{@maximo}"
end
def quantidade
@quantidade = @numeros.length
puts "Quantidade: #{@quantidade}"
end
def media
soma = @numeros.inject(:+)
quantidade = @numeros.length
valor_medio = soma.fdiv(quantidade)
puts "Média: #{valor_medio}"
end
def to_s
puts total,minimo,maximo,quantidade,media
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment