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
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to add an element to the end of an array?
Correct Answer: Option A — push
Detailed Academic Explanation:
push is the correct answer to “Which method in Ruby is used to add an element to the end of an array”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will array.size return in Ruby, if array = [1, 2, 3, 4, 5]?
Correct Answer: Option A — 5
Detailed Academic Explanation:
5 is the correct answer to “What will array.size return in Ruby, if array = [1, 2, 3, 4, 5]”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to access the value associated with a specific key in a hash in Ruby?
Correct Answer: Option C — fetch
Detailed Academic Explanation:
fetch is the correct answer to “Which method is used to access the value associated with a specific key in a hash in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of "hello".reverse in Ruby?
Correct Answer: Option A — "olleh"
Detailed Academic Explanation:
"olleh" is the correct answer to “What is the output of "hello".reverse in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, how do you convert a string to an array of characters?
Correct Answer: Option B — chars
Detailed Academic Explanation:
chars is the correct answer to “In Ruby, how do you convert a string to an array of characters”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following methods is used to merge two hashes together in Ruby?
Correct Answer: Option A — merge
Detailed Academic Explanation:
merge is the correct answer to “Which of the following methods is used to merge two hashes together in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the << operator do when used with a string in Ruby?
Correct Answer: Option A — Appends a character to the end
Detailed Academic Explanation:
Appends a character to the end is the correct answer to “What does the << operator do when used with a string in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a key exists in a hash in Ruby?
Correct Answer: Option D — has_key?
Detailed Academic Explanation:
has_key? is the correct answer to “How do you check if a key exists in a hash in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to remove and return the last element of an array?
Correct Answer: Option A — pop
Detailed Academic Explanation:
pop is the correct answer to “Which method in Ruby is used to remove and return the last element of an array”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the join method do when used with an array in Ruby?
Correct Answer: Option A — Joins all elements into a single string
Detailed Academic Explanation:
Joins all elements into a single string is the correct answer to “What does the join method do when used with an array in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the keys method return when called on a hash in Ruby?
Correct Answer: Option A — Array of all keys
Detailed Academic Explanation:
Array of all keys is the correct answer to “What does the keys method return when called on a hash in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of "hello".length in Ruby?
Correct Answer: Option A — 5
Detailed Academic Explanation:
5 is the correct answer to “What is the output of "hello".length in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to check if an array includes a specific element in Ruby?
Correct Answer: Option A — include?
Detailed Academic Explanation:
include? is the correct answer to “Which method is used to check if an array includes a specific element in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of ["apple", "banana", "cherry"].join(", ") in Ruby?
Correct Answer: Option A — "apple, banana, cherry"
Detailed Academic Explanation:
"apple, banana, cherry" is the correct answer to “What is the output of ["apple", "banana", "cherry"].join(", ") in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which method is used to remove the last element from an array and return it?
Correct Answer: Option A — pop
Detailed Academic Explanation:
pop is the correct answer to “In Ruby, which method is used to remove the last element from an array and return it”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the '<<' operator do when used with arrays in Ruby?
Correct Answer: Option B — Adds an element to the end of the array
Detailed Academic Explanation:
Adds an element to the end of the array is the correct answer to “What does the '<<' operator do when used with arrays in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to check if a key exists in a hash?
Correct Answer: Option D — has_key?
Detailed Academic Explanation:
has_key? is the correct answer to “Which method in Ruby is used to check if a key exists in a hash”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which method is used to add a key-value pair to a hash?
Correct Answer: Option D — store
Detailed Academic Explanation:
store is the correct answer to “In Ruby, which method is used to add a key-value pair to a hash”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the expression `"hello".split` in Ruby?
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What is the result of the expression `"hello".split` in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `include?` method do when used with strings in Ruby?
Correct Answer: Option C — Checks if the string includes another string
Detailed Academic Explanation:
Checks if the string includes another string is the correct answer to “What does the `include?` method do when used with strings in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `capitalize` method do when used with strings?
Correct Answer: Option A — Converts the first character to uppercase
Detailed Academic Explanation:
Converts the first character to uppercase is the correct answer to “In Ruby, what does the `capitalize` method do when used with strings”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which method is used to concatenate two strings?
Correct Answer: Option D — +
Detailed Academic Explanation:
+ is the correct answer to “In Ruby, which method is used to concatenate two strings”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the expression `"hello".length` in Ruby?
Correct Answer: Option A — 5
Detailed Academic Explanation:
5 is the correct answer to “What is the result of the expression `"hello".length` in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `chomp` method do when used with strings in Ruby?
Correct Answer: Option B — Removes newline characters from the end
Detailed Academic Explanation:
Removes newline characters from the end is the correct answer to “What does the `chomp` method do when used with strings in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the pop method do when called on an array in Ruby?
Correct Answer: Option B — Removes the last element of the array
Detailed Academic Explanation:
Removes the last element of the array is the correct answer to “What does the pop method do when called on an array in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which symbol is used to access the value associated with a key in a hash?
Correct Answer: Option A — :
Detailed Academic Explanation:
: is the correct answer to “In Ruby, which symbol is used to access the value associated with a key in a hash”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What method in Ruby is used to join the elements of an array into a single string?
Correct Answer: Option A — join(separator)
Detailed Academic Explanation:
join(separator) is the correct answer to “What method in Ruby is used to join the elements of an array into a single string”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following methods is used to remove a key-value pair from a hash in Ruby?
Correct Answer: Option A — delete(key)
Detailed Academic Explanation:
delete(key) is the correct answer to “Which of the following methods is used to remove a key-value pair from a hash in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `split` method do when called on a string in Ruby?
Correct Answer: Option D — Splits the string into substrings based on a delimiter
Detailed Academic Explanation:
Splits the string into substrings based on a delimiter is the correct answer to “What does the `split` method do when called on a string in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, how can you add a key-value pair to an existing hash?
Correct Answer: Option D — Simply assigning a value to a new key
Detailed Academic Explanation:
Simply assigning a value to a new key is the correct answer to “In Ruby, how can you add a key-value pair to an existing hash”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `each_key` method do when called on a hash in Ruby?
Correct Answer: Option B — Iterates over each key in the hash
Detailed Academic Explanation:
Iterates over each key in the hash is the correct answer to “What does the `each_key` method do when called on a hash in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following methods is used to check if a key exists in a hash in Ruby?
Correct Answer: Option A — has_key?(key)
Detailed Academic Explanation:
has_key?(key) is the correct answer to “Which of the following methods is used to check if a key exists in a hash in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which method is used to convert a string to uppercase?
Correct Answer: Option B — upcase
Detailed Academic Explanation:
upcase is the correct answer to “In Ruby, which method is used to convert a string to uppercase”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `reverse` method do when called on a string in Ruby?
Correct Answer: Option A — Reverses the order of characters in the string
Detailed Academic Explanation:
Reverses the order of characters in the string is the correct answer to “What does the `reverse` method do when called on a string in Ruby”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Arrays can be used to store multiple values in one single variable.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “Arrays can be used to store multiple values in one single variable.”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 36 of 40
★ FPSC
★ PPSC
★ 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]
Correct Answer: Option C — o FALSE
Detailed Academic Explanation:
o FALSE is the correct answer to “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]”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 37 of 40
★ FPSC
★ PPSC
★ 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
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “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”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the given code? string_array = ["a","e","i","o","u"] print string_array[3]
Correct Answer: Option C — o
Detailed Academic Explanation:
o is the correct answer to “What is the output of the given code? string_array = ["a","e","i","o","u"] print string_array[3]”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 39 of 40
★ FPSC
★ PPSC
★ 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
Correct Answer: Option A — Equal
Detailed Academic Explanation:
Equal is the correct answer to “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”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings In Ruby
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the given code? a=[["a","b"]] b=[["e","a"]] print a + b
Correct Answer: Option A — [["a", "b"], ["e", "a"]].
Detailed Academic Explanation:
[["a", "b"], ["e", "a"]]. is the correct answer to “What is the output of the given code? a=[["a","b"]] b=[["e","a"]] print a + b”. This question is standard in competitive examination syllabi for Arrays_ Hashes And Strings In Ruby.
💡Key Conceptual Anchor:Arrays_ Hashes And Strings 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.