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

1/4

Page

Pick an option on a question to see the right 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 will array.size return in Ruby, if array = [1, 2, 3, 4, 5]?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.