Object Oriented Programming III
1.
Which keyword is used for creating a constructor in Ruby?
new
create
init
initialize
2.
In Ruby, what is the purpose of the 'protected' keyword in a module?
To make a module method accessible only within its defining module and its subclasses
To make a module method accessible globally
To make a module method accessible only within the same module
To make a module method accessible only within the including class
3.
What is the purpose of the 'yield_self' method in Ruby?
Executes a block multiple times
Returns a new object with modified attributes
Executes a block with the receiver as an argument and returns the result
Inspects the object's internal state
4.
What is the purpose of the 'prepend' method in Ruby?
To append a module after the class in the method lookup chain
To insert a module before the class in the method lookup chain
To include a module in a class
To create a subclass
5.
How are procs and lambdas different in Ruby?
Procs have mandatory arguments, while lambdas have optional arguments
Procs have optional arguments, while lambdas have mandatory arguments
Procs treat the 'return' keyword differently
Lambdas treat the 'return' keyword differently
6.
How does Ruby handle exceptions and error handling?
Using 'try', 'catch', and 'finally' keywords
Using 'begin', 'rescue', 'ensure', and 'else' keywords
Handling exceptions is not supported in Ruby
Using 'exception' and 'recover' keywords
7.
In Ruby, what is the role of the 'self' keyword inside an instance method?
Refers to the instance itself
Refers to the superclass
Refers to the class
Refers to the parent class
8.
What is the purpose of the 'send' method in Ruby?
To send an email
To invoke a method dynamically
To create a new instance of a class
To define a new method
9.
How does Ruby handle concurrency?
Using threads and the Global Interpreter Lock (GIL)
Using only threads without GIL
Using processes
Using fibers
10.
What does the 'protected' visibility in Ruby allow?
Access only within the defining class
Access within the defining class and its subclasses
Access globally
Access only within the same module
11.
What is the purpose of the 'module_function' in Ruby?
To create an instance of a module
To define a module
To make all module methods available as class methods
To include a module in a class
12.
In Ruby, what is the purpose of the 'included' hook in a module?
To destroy the module
To define methods that will be executed when the module is included
To prevent the module from being included
To check if the module is included in a class
13.
What does the 'extend' method do in Ruby?
Adds a module's methods as class methods
Adds a module's methods as instance methods
Adds a module as a subclass
Extends the length of an array
14.
What is the purpose of the 'super' keyword in the context of module inclusion?
It includes the superclass's methods
It includes the module's methods
It includes both superclass's and module's methods
It prevents module inclusion
15.
How are class variables in Ruby different from instance variables?
Class variables are specific to each instance of a class
Instance variables are shared among all instances of a class
Class variables are shared among all instances of a class
Instance variables are specific to each class
16.
Which method is used to define a class method in Ruby?
def_method
class_method
define_method
self.method
17.
What does the acronym 'SOLID' stand for in object-oriented programming?
Simple Object, Liskov Substitution, Object Inheritance, Dependency Injection
Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
Single Object, Liskov Substitution, Object Inheritance, Dependency Injection
Structured Object, Liskov Substitution, Object Inheritance, Data Interaction
18.
What is the purpose of the 'clone' method in Ruby?
To create a deep copy of an object
To create a shallow copy of an object
To duplicate an object
To copy class definitions
19.
In Ruby, how can you check if an object responds to a certain method?
Using the 'check_method?' method
Using the 'respond_to?' method
Using the 'has_method?' method
Using the 'method_exists?' method
20.
What is the 'symbol' datatype used for in Ruby?
To store numeric values
To define a constant
To create a string
To represent immutable identifiers