Vidyalelo
Ruby Programming · all questions

Arrays, Hashes and Strings in Ruby
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

78

Questions

2/4

Page

Pick an option on a question to see the right answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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]

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.