DEV Community

Discussion on: Explain Ruby's define_method like I'm five

 
rhymes profile image
rhymes • Edited

Having an anonymous module owning a method is a correct approach. It’s not a matter of taste, it’s plain right and clean.

I'm not saying it's wrong or bad, it's obviously right in the context of how Ruby works. I'm just saying it seems weird if you read it.

To add a method named fly to an object mario I have to extend with a method inside an anonymous module that's going to be "injected" inside mario.

In Python this reads: to add a method named fly to an object mario I have to attach it to mario.

This is what I meant with "I find more explicit and clear".

Any way you put it metaprogramming is super cool, in each language I come across of it :-)

Thanks for the reminder about Elixir, I need to get around it sooner or later.