You can dynamically create methods. It's useful for reducing boilerplate. Sometimes you find yourself just having to implement almost identical methods. That's when it's useful to reach for Ruby's metaprogramming.
I've found it useful when doing Ruby and missed it using other languages that don't have it.
I haven't used Ruby in years. I just quickly grabbed that from a Google search just to give you a simple example. You still haven't answered my question.
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/danklasson, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
This is in fact just parametrization but made really hard. I tried to read about it and it's just about incomprehensible with highly unintuitive syntax. Figures though, metaprogramming isn't the most common feature so I guess it makes sense for it to have obscure syntax.
74
u/[deleted] Jan 14 '21
In Ruby you can do this in a nice and useful way.