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?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think the
include
is most useful as used inEnumerable
, 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?