RUBY CERTIFICATION
PRACTICE TEST
COMPLETE
Question 1: In Ruby 3.1, which two objects are falsy in conditional expressions?
Choices:
1) Only nil and false 2) Only nil and 0 3) false and 0 4) nil and an empty string
Correct Answer: Only nil and false
Explanation: Ruby treats only nil and false as falsy. Values such as 0, an empty string, and an empty array are truthy.Page 1
Question 2: What is the value of when both operands are Integer objects in
Ruby 3.1?
Choices:
1) 3
2) 3.5
3) 4 4) 2
Correct Answer: 3
Explanation: Integer division with two Integer operands truncates toward negative innity for positive values, so evaluates to 3.
Question 3: What does the expression 2 ** 3 ** 2 evaluate to in Ruby?
Choices:
1) 64
2) 512
3) 36
4) 729
Correct Answer: 512
Explanation: Exponentiation is right-associative in Ruby, so 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2)
= 2 ** 9 = 512.
Page 2
Question 4: Which literal creates a Symbol named status?
Choices:
1) :status
2) status:
3) 'status' 4) %w(status) Correct Answer: :status Explanation: A Symbol literal is written with a leading colon, so :status creates the Symbol named status.
Question 5: What is the result of [1, 2, 3].map { |n| n * 2 }?
Choices:
1) [1, 2, 3, 2]
2) [2, 4, 6]
3) 6
4) [1, 4, 9]
Correct Answer: [2, 4, 6]
Explanation: Array#map returns a new array containing the result of the block for each element, producing [2, 4, 6].Page 3