DEV Community

Discussion on: Prefer Ruby Class Method or Mix-In Instance Method?

Collapse
 
michaelglass profile image
Michael Glass • Edited

I think the include is most useful as used in Enumerable, e.g. a base class implements a few simple methods, and then by including a module that leverages those simple methods, gets a lot of syntactic sugar on top.

class methods, (consider prefixing your module with module_function and all methods will be accessible as class methods) are a way of pushing Ruby to be more functional.

It's not one vs the other, but rather, two different tools wrapped in one name, module.

Generally, though, I agree with some of the other commenters that class methods are king. But also: if you're going to lean on class methods so much, it might make sense to try to use another language that enforces those patterns, e.g. most functional programming languages. Elixir? Elm?