Class: Ankh::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/ankh/question.rb

Constant Summary collapse

OPERATIONS =
[
  "+",
  "-"
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuestion

Returns a new instance of Question.



10
11
12
13
14
15
16
17
# File 'lib/ankh/question.rb', line 10

def initialize
  @second_number = rand(9)
  @first_number = @second_number + rand(9)
  @operation = OPERATIONS[rand(2)]
  
  @question = "What is #{first_number} #{operation} #{second_number}?"
  @answer = @first_number.send(@operation, @second_number)
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



8
9
10
# File 'lib/ankh/question.rb', line 8

def answer
  @answer
end

#first_numberObject (readonly)

Returns the value of attribute first_number.



8
9
10
# File 'lib/ankh/question.rb', line 8

def first_number
  @first_number
end

#operationObject (readonly)

Returns the value of attribute operation.



8
9
10
# File 'lib/ankh/question.rb', line 8

def operation
  @operation
end

#questionObject (readonly)

Returns the value of attribute question.



8
9
10
# File 'lib/ankh/question.rb', line 8

def question
  @question
end

#second_numberObject (readonly)

Returns the value of attribute second_number.



8
9
10
# File 'lib/ankh/question.rb', line 8

def second_number
  @second_number
end

Class Method Details

.generateObject



19
20
21
# File 'lib/ankh/question.rb', line 19

def self.generate
  new
end