Basic Syntax In Ruby — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Basic Syntax In Ruby — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What symbol is used to denote comments in Ruby?
Correct Answer: Option B — #
Detailed Academic Explanation:
# is the correct answer to “What symbol is used to denote comments in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which symbol is used to concatenate strings in Ruby?
Correct Answer: Option D — <<
Detailed Academic Explanation:
<< is the correct answer to “Which symbol is used to concatenate strings in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'puts' method do in Ruby?
Correct Answer: Option A — Prints to console
Detailed Academic Explanation:
Prints to console is the correct answer to “What does the 'puts' method do in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what is the keyword used to define a method?
Correct Answer: Option D — def
Detailed Academic Explanation:
def is the correct answer to “In Ruby, what is the keyword used to define a method”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is a valid variable name in Ruby?
Correct Answer: Option A — my_variable
Detailed Academic Explanation:
my_variable is the correct answer to “Which of the following is a valid variable name in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'gets' method do in Ruby?
Correct Answer: Option C — Reads input from user
Detailed Academic Explanation:
Reads input from user is the correct answer to “What does the 'gets' method do in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a valid data type in Ruby?
Correct Answer: Option C — Double
Detailed Academic Explanation:
Double is the correct answer to “Which of the following is NOT a valid data type in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for defining a variable in Ruby?
Correct Answer: Option C — name = value
Detailed Academic Explanation:
name = value is the correct answer to “What is the correct syntax for defining a variable in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'print' method do in Ruby?
Correct Answer: Option A — Prints to console
Detailed Academic Explanation:
Prints to console is the correct answer to “What does the 'print' method do in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What symbol is used to denote the end of a statement in Ruby?
Correct Answer: Option A —
Detailed Academic Explanation:
is the correct answer to “What symbol is used to denote the end of a statement in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the correct way to start a single-line comment in Ruby?
Correct Answer: Option C — #
Detailed Academic Explanation:
# is the correct answer to “Which of the following is the correct way to start a single-line comment in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what is the keyword used to define a class?
Correct Answer: Option A — class
Detailed Academic Explanation:
class is the correct answer to “In Ruby, what is the keyword used to define a class”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the correct way to define a constant in Ruby?
Correct Answer: Option A — CONSTANT_NAME = value
Detailed Academic Explanation:
CONSTANT_NAME = value is the correct answer to “Which of the following is the correct way to define a constant in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the default file extension for Ruby files?
Correct Answer: Option C — .rb
Detailed Academic Explanation:
.rb is the correct answer to “What is the default file extension for Ruby files”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to convert a string to uppercase in Ruby?
Correct Answer: Option C — .upcase
Detailed Academic Explanation:
.upcase is the correct answer to “Which method is used to convert a string to uppercase in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to declare a variable in Ruby?
Correct Answer: Option C — name = "value"
Detailed Academic Explanation:
name = "value" is the correct answer to “What is the correct way to declare a variable in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for printing a message to the console?
Correct Answer: Option C — puts("message")
Detailed Academic Explanation:
puts("message") is the correct answer to “What is the correct syntax for printing a message to the console”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you add two numbers in Ruby?
Correct Answer: Option B — a + b
Detailed Academic Explanation:
a + b is the correct answer to “How do you add two numbers in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these operators is used for string concatenation?
Correct Answer: Option A — +
Detailed Academic Explanation:
+ is the correct answer to “Which of these operators is used for string concatenation”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to define a conditional statement in Ruby?
Correct Answer: Option A — if (condition) { code }
Detailed Academic Explanation:
if (condition) { code } is the correct answer to “What is the correct way to define a conditional statement in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for creating a hash in Ruby?
Correct Answer: Option A — {"key1": "value1", "key2": "value2"}
Detailed Academic Explanation:
{"key1": "value1", "key2": "value2"} is the correct answer to “What is the correct syntax for creating a hash in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you access a value from a hash in Ruby?
Correct Answer: Option B — hash["key"]
Detailed Academic Explanation:
hash["key"] is the correct answer to “How do you access a value from a hash in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to define a method in Ruby?
Correct Answer: Option A — def method_name(parameters) code end
Detailed Academic Explanation:
def method_name(parameters) code end is the correct answer to “What is the correct way to define a method in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you call a method in Ruby?
Correct Answer: Option B — object.method_name
Detailed Academic Explanation:
object.method_name is the correct answer to “How do you call a method in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What are the different types of comments in Ruby?
Correct Answer: Option C — Single-line # and multi-line """ """
Detailed Academic Explanation:
Single-line # and multi-line """ """ is the correct answer to “What are the different types of comments in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between =~ and == operators?
Correct Answer: Option A — =~ checks for string pattern matching, == checks for equality
Detailed Academic Explanation:
=~ checks for string pattern matching, == checks for equality is the correct answer to “What is the difference between =~ and == operators”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between nil and false?
Correct Answer: Option A — nil represents absence of value, false represents a boolean value
Detailed Academic Explanation:
nil represents absence of value, false represents a boolean value is the correct answer to “What is the difference between nil and false”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to define a symbol in Ruby?
Correct Answer: Option B — symbol = :value
Detailed Academic Explanation:
symbol = :value is the correct answer to “What is the correct way to define a symbol in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the gem command in Ruby?
Correct Answer: Option A — Installs and manages Ruby libraries
Detailed Academic Explanation:
Installs and manages Ruby libraries is the correct answer to “What is the purpose of the gem command in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to define an array in Ruby?
Correct Answer: Option A — array = ["element1", "element2"]
Detailed Academic Explanation:
array = ["element1", "element2"] is the correct answer to “What is the correct way to define an array in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check the truthiness of a value in Ruby?
Correct Answer: Option C — if value != false
Detailed Academic Explanation:
if value != false is the correct answer to “How do you check the truthiness of a value in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you break out of a loop in Ruby?
Correct Answer: Option B — break()
Detailed Academic Explanation:
break() is the correct answer to “How do you break out of a loop in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the default return value of a method in Ruby?
Correct Answer: Option A — nil
Detailed Academic Explanation:
nil is the correct answer to “What is the default return value of a method in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for accessing a class method?
Correct Answer: Option A — Class.method_name
Detailed Academic Explanation:
Class.method_name is the correct answer to “What is the correct syntax for accessing a class method”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you define a range in Ruby?
Correct Answer: Option B — range = start..end
Detailed Academic Explanation:
range = start..end is the correct answer to “How do you define a range in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for string interpolation in Ruby?
Correct Answer: Option A — "#{variable}"
Detailed Academic Explanation:
"#{variable}" is the correct answer to “What is the correct syntax for string interpolation in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you compare two objects in Ruby?
Correct Answer: Option A — object1 == object2
Detailed Academic Explanation:
object1 == object2 is the correct answer to “How do you compare two objects in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to define a block in Ruby?
Correct Answer: Option A — block { code }
Detailed Academic Explanation:
block { code } is the correct answer to “What is the correct way to define a block in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you pass arguments to a method in Ruby?
Correct Answer: Option A — method_name(arg1, arg2)
Detailed Academic Explanation:
method_name(arg1, arg2) is the correct answer to “How do you pass arguments to a method in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the require keyword in Ruby?
Correct Answer: Option D — Imports external libraries
Detailed Academic Explanation:
Imports external libraries is the correct answer to “What is the purpose of the require keyword in Ruby”. This question is standard in competitive examination syllabi for Basic Syntax In Ruby.
💡Key Conceptual Anchor:Basic Syntax In Ruby
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.