In ruby you can define methods at runtime, to do that, you can use for example the define_method to create at runtime new instance methods.
Why would that be useful?
A classic use is to avoid code repetition. Imagine you have a class that is a basic mixin to help you to make external http requests.
Can you see how much code are we repeating just because of one single parameter?
One way to avoid that is using define_method to create the methods at runtime. Take a look at the following code:
As you can see, we just have to pass the method name as a parameter, and then, in the block definition you pass what will be your method’s parameters.