Basic Syntax In Ruby — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Basic Syntax In Ruby — Part 2 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
How do you get the current date and time in Ruby?
Correct Answer: Option B — time = Time.now
Detailed Academic Explanation:
time = Time.now is the correct answer to “How do you get the current date and time 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
What is the correct way to cast a string to an integer in Ruby?
Correct Answer: Option A — string.to_i
Detailed Academic Explanation:
string.to_i is the correct answer to “What is the correct way to cast a string to an integer 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 is the correct way to declare and initialize a variable in Ruby?
Correct Answer: Option D — variable_name = value
Detailed Academic Explanation:
variable_name = value is the correct answer to “What is the correct way to declare and initialize 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 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which symbol is used for the modulo operation in Ruby?
Correct Answer: Option A — %
Detailed Academic Explanation:
% is the correct answer to “Which symbol is used for the modulo operation in Ruby”. 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 method is used to check if a string contains a specific substring in Ruby?
Correct Answer: Option C — .include?
Detailed Academic Explanation:
.include? is the correct answer to “Which method is used to check if a string contains a specific substring 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
In Ruby, what does the 'if' statement evaluate?
Correct Answer: Option B — Boolean value
Detailed Academic Explanation:
Boolean value is the correct answer to “In Ruby, what does the 'if' statement evaluate”. 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 method is used to convert a string to lowercase in Ruby?
Correct Answer: Option C — .downcase
Detailed Academic Explanation:
.downcase is the correct answer to “Which method is used to convert a string to lowercase 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
In Ruby, what is the correct way to define a constant?
Correct Answer: Option C — constant_name(value)
Detailed Academic Explanation:
constant_name(value) is the correct answer to “In Ruby, what is the correct way to define a constant”. 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 is the output of the expression: "hello" + "world" in Ruby?
Correct Answer: Option A — helloworld
Detailed Academic Explanation:
helloworld is the correct answer to “What is the output of the expression: "hello" + "world" 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
The following syntax is used for multiline comment. =begin iam in a multi line comment =end
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The following syntax is used for multiline comment. =begin iam in a multi line comment =end”. 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 features does the 2.0 version of ruby supports?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Which of the following features does the 2.0 version of ruby supports”. 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
Which of the following is the valid string method?
Correct Answer: Option D — The .irreverse method
Detailed Academic Explanation:
The .irreverse method is the correct answer to “Which of the following is the valid string method”. 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
The .length method is used to check number of characters.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “The .length method is used to check number of characters.”. 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 size of an integer data type in ruby?
Correct Answer: Option B — -230 to 2(30-1)
Detailed Academic Explanation:
-230 to 2(30-1) is the correct answer to “What is the size of an integer 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 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the given code? Ans=Ruby puts "#{Ans} is an oop language" puts "It is very efficient langauge" puts "#{expr} is used on rails platform"
Correct Answer: Option B — Ruby is an oop language It is very efficient langauge undefined local variable
Detailed Academic Explanation:
Ruby is an oop language It is very efficient langauge undefined local variable is the correct answer to “What is the output of the given code? Ans=Ruby puts "#{Ans} is an oop language" puts "It is very efficient langauge" puts "#{expr} is used on rails platform"”. 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
This the right way to comment a single line. “Ruby”.length # I’m a single line comment!
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “This the right way to comment a single line. “Ruby”.length # I’m a single line comment!”. 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
Which of the following is supported by Ruby?
Correct Answer: Option D — All of the Mentioned
Detailed Academic Explanation:
All of the Mentioned is the correct answer to “Which of the following is supported by Ruby”. 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
Space between 2+5 or 2 + 5 is valid but =begin and = begin is not valid.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “Space between 2+5 or 2 + 5 is valid but =begin and = begin is not valid.”. 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
first_name,Last_name=gets.chomp,gets.chomp is the correct way to get the input from the user.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “first_name,Last_name=gets.chomp,gets.chomp is the correct way to get the input from the user.”. 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
Ruby can be used for developing internet and intranet applications.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “Ruby can be used for developing internet and intranet applications.”. 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 output of the given code? "Ruby Language".length = begin calculate length = end
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What is the output of the given code? "Ruby Language".length = begin calculate length = end”. 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
What will be the output of the given code? "I'am learning Ruby Language".reverse.upcase.length
Correct Answer: Option A — 27
Detailed Academic Explanation:
27 is the correct answer to “What will be the output of the given code? "I'am learning Ruby Language".reverse.upcase.length”. 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
Why do we use comments?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Why do we use comments”. 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 to comment multiple lines in ruby?
Correct Answer: Option A — Using multiline comments
Detailed Academic Explanation:
Using multiline comments is the correct answer to “How to comment multiple lines 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 will be the output of the given code? "Come let's learn.reverse Ruby.length language".upcase
Correct Answer: Option C — "COME LET'S LEARN.REVERSE RUBY.LENGTH LANGUAGE"
Detailed Academic Explanation:
"COME LET'S LEARN.REVERSE RUBY.LENGTH LANGUAGE" is the correct answer to “What will be the output of the given code? "Come let's learn.reverse Ruby.length language".upcase”. 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 output of given code? string="I'am Learning RUBY Language".downcase string.upcase
Correct Answer: Option B — "I'AM LEARNING RUBY LANGUAGE"
Detailed Academic Explanation:
"I'AM LEARNING RUBY LANGUAGE" is the correct answer to “What is the output of given code? string="I'am Learning RUBY Language".downcase string.upcase”. 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 output of the code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize first_name.capitalize! print "What's your last name?" last_name=gets.chomp b=last_name.capitalize last_name.capitalize puts "My name is #{first_name} #{last_name}"
Correct Answer: Option B — What's your first name? amil What's your last name? jones My name is Amil Jones
Detailed Academic Explanation:
What's your first name? amil What's your last name? jones My name is Amil Jones is the correct answer to “What is the output of the code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize first_name.capitalize! print "What's your last name?" last_name=gets.chomp b=last_name.capitalize last_name.capitalize puts "My name is #{first_name} #{last_name}"”. 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 output of the following? ruby.reverse
Correct Answer: Option D — Undefined local variable ruby
Detailed Academic Explanation:
Undefined local variable ruby is the correct answer to “What is the output of the following? ruby.reverse”. 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 output of the given code? print "what's your first name?" first_name=gets.chomp a=first_name.capitalize "first_name.capitalize!".reverse puts"My name is #{first_name}"
Correct Answer: Option B — What's your first name? amil My name is amil
Detailed Academic Explanation:
What's your first name? amil My name is amil is the correct answer to “What is the output of the given code? print "what's your first name?" first_name=gets.chomp a=first_name.capitalize "first_name.capitalize!".reverse puts"My name is #{first_name}"”. 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 output of the following? "Iam learning ruby language".length
Correct Answer: Option A — 26
Detailed Academic Explanation:
26 is the correct answer to “What is the output of the following? "Iam learning ruby language".length”. 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
What is the use of .capitalize method?
Correct Answer: Option B — It capitalize on the first letter of the string
Detailed Academic Explanation:
It capitalize on the first letter of the string is the correct answer to “What is the use of .capitalize method”. 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
Which of the following is not a valid datatype?
Correct Answer: Option D — Timedate
Detailed Academic Explanation:
Timedate is the correct answer to “Which of the following is not a valid datatype”. 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
Ruby is an object oriented general purpose programming language.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “Ruby is an object oriented general purpose programming language.”. 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 output of the the given code? puts "My name is #{Name}"
Correct Answer: Option B — Name variable not defined earlier
Detailed Academic Explanation:
Name variable not defined earlier is the correct answer to “What is the output of the the given code? puts "My name is #{Name}"”. 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
What does %Q{ Learn ruby language } represents?
Correct Answer: Option A — " Learn Ruby language "
Detailed Academic Explanation:
" Learn Ruby language " is the correct answer to “What does %Q{ Learn ruby language } represents”. 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
Ruby can be embedded into Hypertext Markup Language(HTML).
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “Ruby can be embedded into Hypertext Markup Language(HTML).”. 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
What is the output of the given code? print "What's your address" city,state,pin=gets.chomp,gets.chomp,gets.chomp puts "Iam from #{city} city, #{state} state, pincode: #{pin} "
Correct Answer: Option C — What's your address? Chennai Tamilnadu 600048 Iam from Chennai city, Tamilnadu state, pincode: 600048
Detailed Academic Explanation:
What's your address? Chennai Tamilnadu 600048 Iam from Chennai city, Tamilnadu state, pincode: 600048 is the correct answer to “What is the output of the given code? print "What's your address" city,state,pin=gets.chomp,gets.chomp,gets.chomp puts "Iam from #{city} city, #{state} state, pincode: #{pin} "”. 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 do we mean by expression substitution?
Correct Answer: Option A — Embedding the value of Ruby expression into a string using #{ }
Detailed Academic Explanation:
Embedding the value of Ruby expression into a string using #{ } is the correct answer to “What do we mean by expression substitution”. 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
What is the output of the given code? my_string=Ruby puts(my_string)
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What is the output of the given code? my_string=Ruby puts(my_string)”. 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 output of the given code? “Ruby”.length #to find the length of given string
Correct Answer: Option B — 4
Detailed Academic Explanation:
4 is the correct answer to “What is the output of the given code? “Ruby”.length #to find the length of given string”. 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.