Skip to main content

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
Question 1 of 40
★ FPSC ★ PPSC

How do you get the current date and time in Ruby?

Question 2 of 40
★ FPSC ★ PPSC

What is the correct way to cast a string to an integer in Ruby?

Question 3 of 40
★ FPSC ★ PPSC

What is the correct way to declare and initialize a variable in Ruby?

Question 4 of 40
★ FPSC ★ PPSC

Which symbol is used for the modulo operation in Ruby?

Question 5 of 40
★ FPSC ★ PPSC

Which method is used to check if a string contains a specific substring in Ruby?

Question 6 of 40
★ FPSC ★ PPSC

In Ruby, what does the 'if' statement evaluate?

Question 7 of 40
★ FPSC ★ PPSC

Which method is used to convert a string to lowercase in Ruby?

Question 8 of 40
★ FPSC ★ PPSC

In Ruby, what is the correct way to define a constant?

Question 9 of 40
★ FPSC ★ PPSC

What is the output of the expression: "hello" + "world" in Ruby?

Question 10 of 40
★ FPSC ★ PPSC

The following syntax is used for multiline comment. =begin iam in a multi line comment =end

Question 11 of 40
★ FPSC ★ PPSC

Which of the following features does the 2.0 version of ruby supports?

Question 12 of 40
★ FPSC ★ PPSC

Which of the following is the valid string method?

Question 13 of 40
★ FPSC ★ PPSC

The .length method is used to check number of characters.

Question 14 of 40
★ FPSC ★ PPSC

What is the size of an integer data type in ruby?

Question 15 of 40
★ 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"

Question 16 of 40
★ FPSC ★ PPSC

This the right way to comment a single line. “Ruby”.length # I’m a single line comment!

Question 17 of 40
★ FPSC ★ PPSC

Which of the following is supported by Ruby?

Question 18 of 40
★ FPSC ★ PPSC

Space between 2+5 or 2 + 5 is valid but =begin and = begin is not valid.

Question 19 of 40
★ FPSC ★ PPSC

first_name,Last_name=gets.chomp,gets.chomp is the correct way to get the input from the user.

Question 20 of 40
★ FPSC ★ PPSC

Ruby can be used for developing internet and intranet applications.

Question 21 of 40
★ FPSC ★ PPSC

What is the output of the given code? "Ruby Language".length = begin calculate length = end

Question 22 of 40
★ FPSC ★ PPSC

What will be the output of the given code? "I'am learning Ruby Language".reverse.upcase.length

Question 23 of 40
★ FPSC ★ PPSC

Why do we use comments?

Question 24 of 40
★ FPSC ★ PPSC

How to comment multiple lines in ruby?

Question 25 of 40
★ FPSC ★ PPSC

What will be the output of the given code? "Come let's learn.reverse Ruby.length language".upcase

Question 26 of 40
★ FPSC ★ PPSC

What is the output of given code? string="I'am Learning RUBY Language".downcase string.upcase

Question 27 of 40
★ 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}"

Question 28 of 40
★ FPSC ★ PPSC

What is the output of the following? ruby.reverse

Question 29 of 40
★ 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}"

Question 30 of 40
★ FPSC ★ PPSC

What is the output of the following? "Iam learning ruby language".length

Question 31 of 40
★ FPSC ★ PPSC

What is the use of .capitalize method?

Question 32 of 40
★ FPSC ★ PPSC

Which of the following is not a valid datatype?

Question 33 of 40
★ FPSC ★ PPSC

Ruby is an object oriented general purpose programming language.

Question 34 of 40
★ FPSC ★ PPSC

What is the output of the the given code? puts "My name is #{Name}"

Question 35 of 40
★ FPSC ★ PPSC

What does %Q{ Learn ruby language } represents?

Question 36 of 40
★ FPSC ★ PPSC

Ruby can be embedded into Hypertext Markup Language(HTML).

Question 37 of 40
★ 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} "

Question 38 of 40
★ FPSC ★ PPSC

What do we mean by expression substitution?

Question 39 of 40
★ FPSC ★ PPSC

What is the output of the given code? my_string=Ruby puts(my_string)

Question 40 of 40
★ FPSC ★ PPSC

What is the output of the given code? “Ruby”.length #to find the length of given string

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 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.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →