Class ArithmeticController
In: app/controllers/arithmetic_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

    # File app/controllers/arithmetic_controller.rb, line 2
 2: def create_sum
 3:   m=rand 10
 4:   n=rand 10
 5:    answer=m+n
 6:    choices=[answer]
 7:   while choices.size < session[:nitems]
 8:     choices << answer/2 + rand(2*answer)
 9:     choices.uniq!
10:   end
11:   sum="#{m}+#{n}"
12:   [sum,answer,choices.sort]
13: end

[Source]

    # File app/controllers/arithmetic_controller.rb, line 33
33:   def extras
34:     @problem = get_problem
35:     @displayed=get_displayed
36:   end

[Source]

    # File app/controllers/arithmetic_controller.rb, line 24
24:   def filechoices?
25:     false
26:   end

[Source]

    # File app/controllers/arithmetic_controller.rb, line 14
14:   def first_time
15:     session[:problem], session[:answer],cho = create_sum
16:     session[:choices]=cho.collect {|n| n.to_s}
17:     if params[:id] && (params[:id].to_i > 0)
18:                         session[:nitems] = params[:id].to_i
19:                 else
20:                         session[:nitems] ||= 5
21:                 end
22:     redirect_to :action => "index"
23:   end

[Source]

    # File app/controllers/arithmetic_controller.rb, line 30
30:  def get_problem
31:    session[:problem] ||= 'default value'
32:  end

[Source]

    # File app/controllers/arithmetic_controller.rb, line 27
27:   def get_title
28:    'what is the answer?'
29:  end

[Source]

    # File app/controllers/arithmetic_controller.rb, line 37
37:   def selected(str)
38:     if str==session[:answer].to_s
39:       session[:displayed]='correct!'
40:       session[:problem], session[:answer],cho = create_sum
41:       session[:choices]=cho.collect {|n| n.to_s}
42:     else
43:       session[:displayed]='wrong!'
44:     end
45:   end

[Validate]