https://www.toptal.com/ruby/ruby-metaprogramming-cooler-than-it-sounds

https://medium.com/swlh/metaprogramming-in-ruby-1b69b1b54202

send / define_method / method_missing

Meta-programming in Ruby is the ability to write programs that can modify themselves or other programs at runtime. Ruby has a rich set of meta-programming features that allow developers to dynamically define classes, add methods and attributes to objects, and even modify the behavior of existing classes and objects.

Here are some of the most common meta-programming techniques in Ruby:

  1. Define methods dynamically: In Ruby, you can dynamically define methods on classes and objects using the "define_method" method. This allows you to define methods based on runtime conditions or user input.
  2. Open classes: Ruby allows you to reopen and modify existing classes and objects at runtime. This is called "monkey patching" and can be a powerful way to extend the behavior of existing code.
  3. Reflection: Ruby provides a rich set of reflection methods that allow you to examine and modify objects at runtime. For example, you can use the "instance_variables" method to get a list of all the instance variables of an object, or the "class_variables" method to get a list of all the class variables of a class.
  4. Metaclasses: In Ruby, every object has a metaclass, which is a special class that defines the behavior of that object's class. By modifying an object's metaclass, you can change the behavior of all instances of that class.
  5. Module mixins: Ruby's module system allows you to create mixins, which are modules that can be included in classes to add behavior. This is a powerful way to add functionality to existing classes without modifying their source code.

Meta-programming can be a powerful tool in Ruby, but it can also make code more difficult to understand and maintain. As with any advanced programming technique, it should be used judiciously and with caution.