Class: Rorr::ReturnValue

Inherits:
Object
  • Object
show all
Defined in:
lib/rorr/return_value.rb

Instance Method Summary collapse

Constructor Details

#initializeReturnValue

Returns a new instance of ReturnValue.



3
4
5
6
# File 'lib/rorr/return_value.rb', line 3

def initialize
  @questions = []
  create_questions
end

Instance Method Details

#startObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rorr/return_value.rb', line 8

def start
  system 'clear'
  UI.puts "\nWelcome to #{"\"What's the return value?\"".light_cyan}"
  UI.puts "Let's check how much do you proficiency in ruby or rails\n"
  Score.start
  @questions.each.with_index(1) do |question, index|
    UI.question(question[:qu], index)
    Score.init(index)
    UI.puts "What's the return value? (Type the #{'Exception'.green} or #{'SyntaxError'.green} if you expect it will return, #{UI.skip}, #{UI.exit})\n\n"
    while answer = UI.gets
      case
      when match_ans?(answer, question[:ans])
        UI.puts 'Correct!'.green
        Score.add_correct
        break
      when answer == 'skip'
        UI.puts 'Skip the Question!'.light_blue
        Score.add_skip
        break
      when answer == '' then UI.puts_with_delay 'Please enter again!'.light_blue
      when answer == 'exit' then exit
      else
        UI.puts_with_delay 'Error, Please enter again!'.light_red
        Score.add_retry
      end
    end
    Score.add_report
    UI.solution(question[:sol])
  end
  Score.finish
  UI.report
end