Skip to main content

Data Types And Variables In Ruby MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Data Types And Variables In Ruby 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

What is the output of the expression: "5" + "2" in Ruby?

Question 2 of 40
★ FPSC ★ PPSC

What is the data type of the value 3.14 in Ruby?

Question 3 of 40
★ FPSC ★ PPSC

What is the default value of a variable in Ruby if not initialized?

Question 4 of 40
★ FPSC ★ PPSC

Which symbol is used to declare a variable in Ruby?

Question 5 of 40
★ FPSC ★ PPSC

What does the 'nil' value represent in Ruby?

Question 6 of 40
★ FPSC ★ PPSC

What is the method used to convert a string to an integer in Ruby?

Question 7 of 40
★ FPSC ★ PPSC

What is the method used to convert a string to a float in Ruby?

Question 8 of 40
★ FPSC ★ PPSC

What is the data type of the value true in Ruby?

Question 9 of 40
★ FPSC ★ PPSC

What is the method used to convert a value to string in Ruby?

Question 10 of 40
★ FPSC ★ PPSC

What is the result of the expression: 5 / 2 in Ruby?

Question 11 of 40
★ FPSC ★ PPSC

Which of the following is the correct way to declare a constant in Ruby?

Question 12 of 40
★ FPSC ★ PPSC

Which method is used to check if a variable is nil in Ruby?

Question 13 of 40
★ FPSC ★ PPSC

What is the method used to check the data type of a variable in Ruby?

Question 14 of 40
★ FPSC ★ PPSC

What is the method used to check if a variable is defined in Ruby?

Question 15 of 40
★ FPSC ★ PPSC

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

Question 16 of 40
★ FPSC ★ PPSC

Which of the following is a valid way to declare a variable in Ruby?

Question 17 of 40
★ FPSC ★ PPSC

What is the data type of the value "Hello, World" in Ruby?

Question 18 of 40
★ FPSC ★ PPSC

What is the method used to check if a variable is empty in Ruby?

Question 19 of 40
★ FPSC ★ PPSC

What is the correct way to concatenate two strings in Ruby?

Question 20 of 40
★ FPSC ★ PPSC

What is the output of the expression: "5".to_i + 2 in Ruby?

Question 21 of 40
★ FPSC ★ PPSC

What is the correct way to declare a variable in Ruby without assigning a value?

Question 22 of 40
★ FPSC ★ PPSC

What is the method used to convert a string to lowercase in Ruby?

Question 23 of 40
★ FPSC ★ PPSC

Which of the following is the correct way to declare a variable in Ruby with a default value?

Question 24 of 40
★ FPSC ★ PPSC

What is the method used to check if a variable is numeric in Ruby?

Question 25 of 40
★ FPSC ★ PPSC

What is the output of the expression: "10" * 3 in Ruby?

Question 26 of 40
★ FPSC ★ PPSC

Which method is used to convert a string to an array of characters in Ruby?

Question 27 of 40
★ FPSC ★ PPSC

What is the method used to check if a variable is of a specific class in Ruby?

Question 28 of 40
★ FPSC ★ PPSC

Which of the following is the correct way to define a variable in Ruby?

Question 29 of 40
★ FPSC ★ PPSC

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

Question 30 of 40
★ FPSC ★ PPSC

What is the result of the expression: 10 % 3 in Ruby?

Question 31 of 40
★ FPSC ★ PPSC

In Ruby, what is the keyword used to define a constant?

Question 32 of 40
★ FPSC ★ PPSC

Which of the following is the correct way to define a range in Ruby?

Question 33 of 40
★ FPSC ★ PPSC

What does the 'return' keyword do in Ruby methods?

Question 34 of 40
★ FPSC ★ PPSC

What is the correct way to declare and initialize an array in Ruby?

Question 35 of 40
★ FPSC ★ PPSC

In Ruby, what is the default file extension for Ruby files?

Question 36 of 40
★ FPSC ★ PPSC

What does the 'chomp' method do in Ruby?

Question 37 of 40
★ FPSC ★ PPSC

What is the correct syntax for a multiline comment in Ruby?

Question 38 of 40
★ FPSC ★ PPSC

Which method is used to find the length of an array in Ruby?

Question 39 of 40
★ FPSC ★ PPSC

What is the output of the expression: 7 / 2 in Ruby?

Question 40 of 40
★ FPSC ★ PPSC

In Ruby, what is the keyword used to define a loop that repeats until a condition is true?

✓ 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 →