Class: PreguntaS

Inherits:
Pregunta show all
Defined in:
lib/exam/pregunta.rb

Overview

Pregunta de respuesta múltiple

Instance Attribute Summary collapse

Attributes inherited from Pregunta

#correcta, #df, #pr

Instance Method Summary collapse

Methods inherited from Pregunta

#<=>, #==, #resp_correcta?

Constructor Details

#initialize(pregunta, dificultad = 5) ⇒ PreguntaS

Constructor



8
9
10
11
12
# File 'lib/exam/pregunta.rb', line 8

def initialize (pregunta, dificultad = 5)
  super
  @re = Array.new(0) 
#inicializamos un array con 0 elementos para las respuestas
end

Instance Attribute Details

#reObject (readonly)

Returns the value of attribute re.



5
6
7
# File 'lib/exam/pregunta.rb', line 5

def re
  @re
end

Instance Method Details

#addr(respuesta) ⇒ Object

Agrega una respuesta adicional a la pregunta



20
21
22
# File 'lib/exam/pregunta.rb', line 20

def addr (respuesta)
  @re.push(respuesta)
end

#pregObject

Método que devuelve la pregunta como String



15
16
17
# File 'lib/exam/pregunta.rb', line 15

def preg
  "Pregunta: #{@pr}"
end

#respObject

Devuelve las respuestas como String



25
26
27
28
29
30
31
# File 'lib/exam/pregunta.rb', line 25

def resp
  respuestas = ""
  for i in (0..(@re.length - 1))
    respuestas += "#{i+1}) #{@re[i]}\n"
  end
  respuestas
end

#to_sObject

Muestra la pregunta y sus posibles respuestas como una String



34
35
36
# File 'lib/exam/pregunta.rb', line 34

def to_s
  preg + "\n\n" + resp
end