Skip to main content

Arrays_ Hashes And Strings In Ruby — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Arrays_ Hashes And Strings 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
Question 1 of 40
★ FPSC ★ PPSC

Which method in Ruby is used to add an element to the end of an array?

Question 2 of 40
★ FPSC ★ PPSC

What will array.size return in Ruby, if array = [1, 2, 3, 4, 5]?

Question 3 of 40
★ FPSC ★ PPSC

Which method is used to access the value associated with a specific key in a hash in Ruby?

Question 4 of 40
★ FPSC ★ PPSC

What is the output of "hello".reverse in Ruby?

Question 5 of 40
★ FPSC ★ PPSC

In Ruby, how do you convert a string to an array of characters?

Question 6 of 40
★ FPSC ★ PPSC

Which of the following methods is used to merge two hashes together in Ruby?

Question 7 of 40
★ FPSC ★ PPSC

What does the << operator do when used with a string in Ruby?

Question 8 of 40
★ FPSC ★ PPSC

How do you check if a key exists in a hash in Ruby?

Question 9 of 40
★ FPSC ★ PPSC

Which method in Ruby is used to remove and return the last element of an array?

Question 10 of 40
★ FPSC ★ PPSC

What does the join method do when used with an array in Ruby?

Question 11 of 40
★ FPSC ★ PPSC

What does the keys method return when called on a hash in Ruby?

Question 12 of 40
★ FPSC ★ PPSC

What is the output of "hello".length in Ruby?

Question 13 of 40
★ FPSC ★ PPSC

Which method is used to check if an array includes a specific element in Ruby?

Question 14 of 40
★ FPSC ★ PPSC

What is the output of ["apple", "banana", "cherry"].join(", ") in Ruby?

Question 15 of 40
★ FPSC ★ PPSC

In Ruby, which method is used to remove the last element from an array and return it?

Question 16 of 40
★ FPSC ★ PPSC

What does the '<<' operator do when used with arrays in Ruby?

Question 17 of 40
★ FPSC ★ PPSC

Which method in Ruby is used to check if a key exists in a hash?

Question 18 of 40
★ FPSC ★ PPSC

In Ruby, which method is used to add a key-value pair to a hash?

Question 19 of 40
★ FPSC ★ PPSC

What is the result of the expression `"hello".split` in Ruby?

Question 20 of 40
★ FPSC ★ PPSC

What does the `include?` method do when used with strings in Ruby?

Question 21 of 40
★ FPSC ★ PPSC

In Ruby, what does the `capitalize` method do when used with strings?

Question 22 of 40
★ FPSC ★ PPSC

In Ruby, which method is used to concatenate two strings?

Question 23 of 40
★ FPSC ★ PPSC

What is the result of the expression `"hello".length` in Ruby?

Question 24 of 40
★ FPSC ★ PPSC

What does the `chomp` method do when used with strings in Ruby?

Question 25 of 40
★ FPSC ★ PPSC

What does the pop method do when called on an array in Ruby?

Question 26 of 40
★ FPSC ★ PPSC

In Ruby, which symbol is used to access the value associated with a key in a hash?

Question 27 of 40
★ FPSC ★ PPSC

What method in Ruby is used to join the elements of an array into a single string?

Question 28 of 40
★ FPSC ★ PPSC

Which of the following methods is used to remove a key-value pair from a hash in Ruby?

Question 29 of 40
★ FPSC ★ PPSC

What does the `split` method do when called on a string in Ruby?

Question 30 of 40
★ FPSC ★ PPSC

In Ruby, how can you add a key-value pair to an existing hash?

Question 31 of 40
★ FPSC ★ PPSC

What does the `each_key` method do when called on a hash in Ruby?

Question 32 of 40
★ FPSC ★ PPSC

Which of the following methods is used to check if a key exists in a hash in Ruby?

Question 33 of 40
★ FPSC ★ PPSC

In Ruby, which method is used to convert a string to uppercase?

Question 34 of 40
★ FPSC ★ PPSC

What does the `reverse` method do when called on a string in Ruby?

Question 35 of 40
★ FPSC ★ PPSC

Arrays can be used to store multiple values in one single variable.

Question 36 of 40
★ FPSC ★ PPSC

What is the output of the given code? string_array = ["a","e","i","o","u"] boolean_array = ["True","False"] puts string_array[3] puts boolean_array[1]

Question 37 of 40
★ FPSC ★ PPSC

What will be the output of the following? array1 = [1,2,3] array2 = [0,0,0] if array1 >= array2 print "Greater or equal" else print "Not equal" end

Question 38 of 40
★ FPSC ★ PPSC

What is the output of the given code? string_array = ["a","e","i","o","u"] print string_array[3]

Question 39 of 40
★ FPSC ★ PPSC

What is the output of the given code? a=["hey", "ruby", "language"] b=["hey", "ruby", "language"] if a==b print "Equal" else print "Not equal" end

Question 40 of 40
★ FPSC ★ PPSC

What is the output of the given code? a=[["a","b"]] b=[["e","a"]] print a + b

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