Object Oriented Programming IV
1.
What is the purpose of the 'self' keyword in Ruby?
To refer to the current instance of the class
To refer to the superclass
To refer to the current class
To refer to the parent class
2.
Which keyword is used for defining a constant in Ruby?
constant
const
define_const
const_define
3.
Which method is used to remove the last element from an array in Ruby?
remove
pop
delete
truncate
4.
In Ruby, how can you define a class method?
Using the 'self' keyword within the class
Using the 'static' keyword
Using the 'class_method' keyword
Using the 'def' keyword with the class name
5.
What is the purpose of the 'protected' keyword in Ruby?
To make a method accessible only within the same module
To make a method accessible globally
To make a method accessible only within the defining class
To make a method accessible only within the defining class and its subclasses
6.
In Ruby, what does the 'super' keyword do in the context of method inheritance?
Prevents method inheritance
Overrides the superclass's method
Creates a new method in the subclass
Calls the superclass's method with the same name
7.
What is the role of the 'include' keyword in Ruby?
To include a module's methods and constants
To inherit from another class
To include a class's methods and constants
To include a superclass's methods
8.
How are class variables in Ruby different from instance variables?
Instance variables are shared among all instances of a class
Class variables are shared among all instances of a class
Class variables are specific to each instance of a class
Instance variables are specific to each class
9.
What is the purpose of the 'tap' method in Ruby?
Performs a shallow copy of the object
Returns a new object with modified attributes
Yields the object to a block and returns the original object
Inspects the object's internal state
10.
What is the purpose of the 'Module#included' callback in Ruby?
Executes code when a method is included in a module
Executes code when a class is included in another class
Executes code when a module is extended
Executes code when a module is included in a class
11.
What is the significance of the 'initialize' method in Ruby?
It is used to define class variables
It is called to destroy an object
It is called when a new object is created to set up its initial state
It is called when an object is about to be destroyed
12.
How does Ruby support multiple inheritance?
By using the 'inherits' keyword
By allowing a class to inherit from multiple modules
By using the 'extends' keyword
By using the 'multiple' keyword
13.
What is the purpose of the 'freeze' method in Ruby?
To freeze an object and prevent further modifications
To defrost an object
To duplicate an object
To thaw an object
14.
What is the purpose of the 'autoload' feature in Ruby?
To load modules or classes at program startup
To unload modules or classes
To load modules or classes on-demand
To define a constant
15.
In Ruby, what is the purpose of the 'module_function' declaration?
To include a module in a class
To create an instance of a module
To make all module methods available as class methods
To define a module
16.
What is encapsulation in object-oriented programming?
Combining data and methods into a single unit
Exposing implementation details and hiding the interface
Hiding implementation details and exposing the interface
Separating data and methods into different units
17.
What is the purpose of the 'clone' method in Ruby?
To create a shallow copy of an object
To create a deep copy of an object
To duplicate an object
To copy class definitions
18.
What is the purpose of the 'module' keyword in Ruby?
To define a module
To create an instance of a class
To declare a namespace
To include a module in another module
19.
What is the purpose of the 'singleton_method_added' hook in Ruby?
To check if a singleton method is added
To execute code when a singleton method is added
To prevent the addition of singleton methods
To define a new singleton method
20.
What is the purpose of the 'method_missing' method in Ruby?
Deletes a method from a class
Handles calls to undefined methods dynamically
Renames a method in a class
Handles errors during method invocation