Class: Exam::Test
Overview
create a Test
Direct Known Subclasses
Instance Attribute Summary collapse
-
#correcta ⇒ Object
Returns the value of attribute correcta.
-
#nivel ⇒ Object
Returns the value of attribute nivel.
-
#pregunta ⇒ Object
Returns the value of attribute pregunta.
-
#respuestas ⇒ Object
Returns the value of attribute respuestas.
Instance Method Summary collapse
- #<=>(a) ⇒ Object
- #==(a) ⇒ Object
- #check_ans(c) ⇒ Object
-
#initialize(pregunta, correcta, respuestas, nivel = nil) ⇒ Test
constructor
A new instance of Test.
- #to_s ⇒ Object
Constructor Details
#initialize(pregunta, correcta, respuestas, nivel = nil) ⇒ Test
Returns a new instance of Test.
17 18 19 20 21 22 |
# File 'lib/exam/test.rb', line 17 def initialize(pregunta, correcta, respuestas, nivel=nil) @pregunta = pregunta @correcta = correcta @respuestas = respuestas.shuffle @nivel = nivel end |
Instance Attribute Details
#correcta ⇒ Object
Returns the value of attribute correcta.
7 8 9 |
# File 'lib/exam/test.rb', line 7 def correcta @correcta end |
#nivel ⇒ Object
Returns the value of attribute nivel.
7 8 9 |
# File 'lib/exam/test.rb', line 7 def nivel @nivel end |
#pregunta ⇒ Object
Returns the value of attribute pregunta.
7 8 9 |
# File 'lib/exam/test.rb', line 7 def pregunta @pregunta end |
#respuestas ⇒ Object
Returns the value of attribute respuestas.
7 8 9 |
# File 'lib/exam/test.rb', line 7 def respuestas @respuestas end |
Instance Method Details
#<=>(a) ⇒ Object
9 10 11 |
# File 'lib/exam/test.rb', line 9 def <=> (a) @nivel <=> a.nivel end |
#==(a) ⇒ Object
13 14 15 |
# File 'lib/exam/test.rb', line 13 def == (a) @pregunta==a.pregunta && @correcta==a.correcta && @respuestas.should =~ a.respuestas end |
#check_ans(c) ⇒ Object
24 25 26 |
# File 'lib/exam/test.rb', line 24 def check_ans(c) return (c == @correcta) end |
#to_s ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/exam/test.rb', line 28 def to_s texto = "Pregunta: #{@pregunta} \n" for i in 0..@respuestas.size-1 texto = texto + "\t #{i+1}) #{@respuestas[i]} \n" end return texto end |