Ruby MCQ
Ruby MCQ
3. Operators
4. Control Structures
Sample MCQ: Which of the following is the correct way to write an if statement
in Ruby?
o A) if x > 10 then
o B) if x > 10 do
o C) if x > 10
o D) if x greater than 10
Answer: C) if x > 10
5. Loops (for, while, until)
Sample MCQ: Which loop continues until the condition becomes false in Ruby?
o A) for loop
o B) while loop
o C) until loop
o D) break loop
Answer: C) until loop
6. Methods
Sample MCQ: In Ruby, a class inherits from another class using which symbol?
o A) :
o B) @
o C) <<
o D) <
Answer: D) <
Sample MCQ: What is the method used to print a message to the console in Ruby?
o A) print
o B) echo
o C) puts
o D) write
Answer: C) puts
Sample MCQ: What syntax does Ruby use for regular expressions?
o A) /regex/
o B) |regex|
o C) !regex!
o D) $regex$
Answer: A) /regex/