Metaprogramming III
1.
How can you dynamically define class methods in Ruby within a module?
Using `self.method_name`
Using `def self.method_name`
Using `module_function`
Using `define_singleton_method`
2.
What is the purpose of the `class_eval` method in Ruby metaprogramming?
Access class constants
Evaluate code in the context of a class
Define instance variables
Create new instances of a class
3.
How can you dynamically define private methods in Ruby?
Using the `private` keyword
Using `define_private_method` method
Using `private_method` keyword
Using `class_eval` method
4.
How can you dynamically define class constants in Ruby within a module?
Using `module ConstantName`
Using `define_constant` method
Using `const_set` method
Using `Module.define_constant`
5.
What does the `define_singleton_method` allow you to do in Ruby?
Define a method on a specific object
Define a method on a class
Define a method on a module
Define a method on an instance variable
6.
How can you dynamically define a new class in Ruby?
Using `Class.new`
Using `create_class` method
Using `define_class` method
Using `class.create`
7.
In Ruby metaprogramming, what does the `included` callback method provide?
Access to class constants
A callback when a module is included in a class
Dynamic modification of class variables
Automatic inheritance of instance methods
8.
Which method is commonly used to dynamically define getter methods in Ruby?
attr_reader
attr_writer
attr_accessor
instance_variable_get
9.
What is the purpose of the `prepend` method in Ruby metaprogramming?
Remove a module from the inheritance chain
Add a module to the inheritance chain before the class
Append a module to the end of the inheritance chain
Create a new instance of a module
10.
What is the purpose of the `method_defined?` method in Ruby metaprogramming?
Invoke a method dynamically
Access the source code of a method
Remove a method from a class
Check if a method is defined in a class or module
11.
How can you dynamically undefine a method in Ruby?
Using `undefine_method`
Using `delete_method`
Using `remove_method`
Using `undef_method`
12.
What is a common use case for the `instance_variable_set` method in Ruby metaprogramming?
Access class constants
Retrieve the value of an instance variable by name
Define new instance variables
Set the value of an instance variable dynamically
13.
In Ruby, what does the `alias` keyword allow you to do?
Invoke a method dynamically
Define a new method
Remove a method from a class
Create an alias for an existing method
14.
How can you dynamically define private methods in Ruby?
Using the `private` keyword
Using `define_private_method` method
Using `private_method` keyword
Using `class_eval` method
15.
What is a common use case for the `instance_variable_get` method in Ruby metaprogramming?
Define new instance variables
Set the value of an instance variable
Retrieve the value of an instance variable by name
Access class constants
16.
In Ruby metaprogramming, what does the `send` method with three arguments allow you to do?
Modify class constants
Access instance variables
Define new classes
Invoke a method dynamically with specified arguments
17.
What is the purpose of the `extend` method in Ruby metaprogramming?
Create a new instance of a module
Add a module to the inheritance chain before the class
Remove a module from the inheritance chain
Add a module's methods as instance methods
18.
How can you dynamically define class constants in Ruby within a module?
Using `module ConstantName`
Using `define_constant` method
Using `const_set` method
Using `Module.define_constant`
19.
What is the purpose of the `class_eval` method in Ruby metaprogramming?
Access class constants
Evaluate code in the context of a class
Define instance variables
Create new instances of a class
20.
What is the purpose of the `define_singleton_method` in Ruby metaprogramming?
Define a method on a specific object
Define a method on a class
Define a method on a module
Define a method on an instance variable