Metaprogramming IV
1.
What is the purpose of the `method_missing` method in Ruby metaprogramming?
Deletes existing methods
Handles calls to undefined methods
Accesses instance variables directly
Generates random method names
2.
How can you dynamically define a class method in Ruby?
Using `self.method_name` syntax
Using `def self.method_name` syntax
Using `define_singleton_method`
Using `class.create_method`
3.
How can you access the metaclass of an object in Ruby?
Using the `meta` keyword
Using the `class` keyword
Using the `metaclass` method
Using the `singleton_class` method
4.
In metaprogramming, what is a use case for the `define_singleton_method`?
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
5.
How can you dynamically define a new class in Ruby?
Using `define_class` method
Using `create_class` method
Using `Class.new`
Using `class.create`
6.
What is metaprogramming in Ruby?
A tool for debugging
A method for code optimization
A technique to write code that generates code dynamically
A way to create project metadata
7.
In Ruby, what does the term `self` refer to inside a class method?
An instance of the class
The class itself
The superclass
An object of the same name
8.
What is a metaclass in Ruby?
An instance of a class
A class that holds instance methods
A class that holds class methods
A module for code organization
9.
What does the `class_eval` method do in Ruby metaprogramming?
Evaluates code in the context of a class
Accesses class constants
Defines instance variables
Creates new instances of a class
10.
How does the `define_method` method differ from using `def` in Ruby?
`def` is used for defining singleton methods
`define_method` allows dynamic method creation
Both are interchangeable
`def` is used for defining class methods
11.
How can you dynamically create instance methods in Ruby using `define_method`?
Use `define_instance_method` keyword
Inside the class definition, call `define_method` with the method name and a block
Call `define_method` outside the class definition
Invoke `define_method` on an instance of the class
12.
In Ruby, what does the `singleton_class` method provide access to?
The instance variables of an object
The superclass of a class
The metaclass of an object
The constants of a class
13.
What is the role of `method_missing` in metaprogramming?
Defines new methods
Deletes existing methods
Handles calls to undefined methods
Accesses class variables directly
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.
In metaprogramming, what is the purpose of the `instance_eval` method?
Evaluates code in the context of an instance
Accesses class constants
Defines instance variables
Creates new instances of a class
16.
What is a common use case for the `instance_variable_set` method in Ruby metaprogramming?
Removing instance variables
Accessing the value of an instance variable
Defining new instance variables
Setting the value of an instance variable dynamically
17.
What is a metaprogramming technique to make code DRY in Ruby?
Using `method_missing`
Using `define_method`
Using `instance_eval`
Using `class_eval`
18.
How can you create a class method in Ruby using `class_eval`?
Inside the class definition, call `class_eval` with the method name and a block
Use `class_method` keyword
Call `class_eval` outside the class definition
Invoke `class_eval` on an instance of the class
19.
What does the `class << obj` syntax do in Ruby metaprogramming?
Accesses the superclass of the object
Defines a new class
Invokes the constructor of the object
Opens the metaclass of the object
20.
What does the `class_eval` method allow you to do in Ruby metaprogramming?
Create new instances of a class
Access class constants
Define instance variables
Evaluate code in the context of a class