Metaprogramming I
1.
In Ruby, what does the `method_missing` method allow you to do?
Override built-in methods
Access private methods
Handle method calls for undefined methods
Define class-level methods
2.
In Ruby, what does the `alias_method` allow you to do?
Remove a method from a class
Define a new method
Create an alias for an existing method
Invoke a method dynamically
3.
How can you access the list of methods defined in a class dynamically in Ruby?
Using `list_methods` method
Using `methods` method
Using `get_methods` method
Using `class_methods` method
4.
How can you dynamically define instance methods in Ruby?
Using `def method_name`
Using `define_method`
Using `self.method_name`
Using `class << self; def method_name; end; end`
5.
What is the purpose of the `prepend` method in Ruby metaprogramming?
Create a new instance of a module
Remove a module from the inheritance chain
Append a module to the end of the inheritance chain
Add a module to the inheritance chain before the class
6.
How can you dynamically define class variables in Ruby?
Using `@@variable_name` syntax
Using `class_variable_set` method
Using `define_class_variable` method
Using `Class.define_variable`
7.
What is the purpose of the `method_defined?` method in Ruby?
Remove a method from a class
Access the source code of a method
Check if a method is defined in a class
Invoke a method dynamically
8.
Which module in Ruby provides a way to define methods that can be used as if they were instance methods of a class?
Kernel
Module
Object
BasicObject
9.
What is the purpose of the `extend` method in Ruby metaprogramming?
Add a module's methods as class methods
Add a module to the inheritance chain before the class
Remove a module from the inheritance chain
Create a new instance of a module
10.
What does the term `metaprogramming` mean in Ruby?
A tool for managing project metadata
A programming language feature for advanced debugging
A method for optimizing code execution
A technique to write programs that write programs
11.
Which method in Ruby is commonly used for defining getter methods dynamically?
attr_reader
attr_writer
attr_accessor
instance_variable_get
12.
What is the primary purpose of the `define_method` in Ruby metaprogramming?
Accessing class constants
Defining a new method dynamically
Creating class variables
Modifying existing methods
13.
Which module in Ruby provides reflection capabilities and is commonly used in metaprogramming?
Module
Reflection
Kernel
Object
14.
What does the `send` method in Ruby allow you to do?
Access instance variables
Invoke a method dynamically
Define new classes
Modify class constants
15.
How can you dynamically define class methods in Ruby?
Using `self.method_name`
Using `def self.method_name`
Using `class << self; def method_name; end; end`
Using `define_method`
16.
What is the purpose of the `class_eval` method in Ruby metaprogramming?
Create new instances of a class
Access class constants
Define instance variables
Evaluate code in the context of a class
17.
In Ruby, what does the `const_get` method allow you to do?
Define new constants
Access instance variables
Retrieve the value of a constant by name
Invoke class methods
18.
What is a common use case for the `instance_eval` method in Ruby?
Defining new classes
Accessing class variables
Modifying the behavior of a specific object
Invoking class methods
19.
What does the `included` method in Ruby modules provide for metaprogramming?
Automatic inheritance of instance methods
Access to class constants
Dynamic modification of class variables
A callback when the module is included in a class
20.
How can you dynamically define a new class in Ruby?
Using `class.new`
Using `create_class` method
Using `Class.define`
Using `Class.new`