class Examen::Exam

Attributes

preguntas[R]
respuescorrectas[R]

Public Class Methods

new(args) click to toggle source
# File lib/examen/exam.rb, line 13
def initialize (args)
    @preguntas = args[:preguntas] 
    @respuescorrectas=args[:respuescorrectas]
end

Public Instance Methods

compresp(resp) click to toggle source
# File lib/examen/exam.rb, line 31
def compresp(resp)
    correctas=0 
    i=0
    n=0
    
    while n < 5 do
        if @respuescorrectas[i] == resp[i]
            correctas+=1
        end
        i+=1 
        n+=1
    end
    if correctas < (i/2)+1
        mensaje = "Ha suspendido el examen: #{correctas}/#{i}"
    else
        if correctas == i
             mensaje = "Su nota es: Sobresaliente 10"
        else
            mensaje = "Ha aprobado el examen: #{correctas}/#{i}"
        end
    end
    mensaje
end
insertQuestion(question) click to toggle source
# File lib/examen/exam.rb, line 18
def insertQuestion(question)
    nodo=Nodo.new(question)
    nodoInsertado = @preguntas.pushf(nodo)
    nodoInsertado.value
end
insertQuestion2(question) click to toggle source
# File lib/examen/exam.rb, line 24
def insertQuestion2(question)
    nodo=Nodo.new(question)
    nodoInsertado = @preguntas.push(nodo)
    nodoInsertado.value
end
invertir() click to toggle source
# File lib/examen/exam.rb, line 66
def invertir
    aux = @preguntas.fin
    respuesta = ""
    respuesta += aux.value.to_s
    respuesta += "\n"
    while (aux != @preguntas.inicio) do
        aux = aux.prev
        respuesta += aux.value.to_s
        respuesta += "\n"
    end
    respuesta
    end
invertirfuncional(arr) click to toggle source
# File lib/examen/exam.rb, line 79
def invertirfuncional(arr)
        #aux=%W(#{arr})
        #lambda {|a| a.map(&:reverse) }.call(aux.reverse)
       arr2=Array.new
       arr.reverse_each do |z|
       arr2.push(z)
       end
       arr2
    end
invertirlambda(lista) click to toggle source

stackoverflow.com/questions/13769378/storing-methods-in-a-lambda-and-sending-to-an-object

# File lib/examen/exam.rb, line 93
def invertirlambda(lista)
    aux=Array.new
    aux.push(lista)
    invertir = lambda { reverse } #es igual decir lambda ->
    aux=lista.instance_exec(&invertir)
    
    return aux
    
        
end
respu() click to toggle source
# File lib/examen/exam.rb, line 61
def respu       
    @respuescorrectas
end