Ruby MCQ Test: Ruby MCQs - Practice Questions
1. What is the purpose of the '__FILE__' constant in Ruby?
2. What is the purpose of the 'begin' and 'rescue' keywords in Ruby?
3. Which method is used to iterate over each element of an array in Ruby?
4. What is Ruby primarily known for?
5. What is the Ruby equivalent of 'null' in some other programming languages?
6. In Ruby, what is the 'singleton class' or 'eigenclass'?
7. Which of the following is NOT a valid way to define a variable in Ruby?
8.
9.
10. Which Ruby operator is used to check if an object belongs to a specific class or module?
11.
12. What is the purpose of the 'include' module in Ruby?
13. What is the Ruby operator for exponentiation?
14. In Ruby, what is the 'yield' keyword used for in a method definition?
15. Which operator is used for concatenating strings in Ruby?
16. In Ruby, what is the purpose of the 'module_function' keyword?
17. Which operator is used for the logical 'OR' operation in Ruby?
18. What is the purpose of the 'each' method in Ruby?
19. In Ruby, what is the 'self' keyword used for?
20. In Ruby, what is the purpose of the 'puts' method?
21. What is the purpose of the 'unless' keyword in Ruby?
22. What does the 'attr_reader' method do in Ruby?
23. In Ruby, what does 'attr_accessor' do?
24. Which method is used to convert a string to uppercase in Ruby?
25. In Ruby, what does 'self.included(base)' method indicate in a module?
26. What is the difference between '==', '===' and 'eql?' in Ruby?
27. What does the 'nil' value represent in Ruby?
28. What is the symbol used to represent the current object in Ruby?
29. What is the Ruby operator for equality?
30. What does the 'super' keyword do in Ruby?
31. What is the result of 5 + 3 in Ruby?
32. What is the purpose of the 'attr_accessor' keyword in Ruby?
33. Which Ruby data structure is similar to an array but allows you to associate values with keys?
34. What is the output of the code 'puts 2 * 3' in Ruby?
35. What is the 'splat' operator (*) used for in Ruby?
36. What is the purpose of the 'map' method in Ruby?
37. In Ruby, what is the purpose of the 'next' keyword within a loop?
38. What is the purpose of the 'throw' and 'catch' keywords in Ruby?
39. In Ruby, how do you define a range from 1 to 10?
40. In Ruby, what is an 'if' statement used for?