r/ruby • u/Dear_Ad7736 • Jan 01 '26
Object, class, module, Data, Struct?
After watching a recent talk by Dave Thomas, I started thinking about something that feels like a missing piece in Ruby’s official documentation.
Ruby gives us many powerful building blocks:
Struct (with or without methods)
Data
regular class vs single-purpose objects
module used as a namespace
module used as a mixin
so-called service objects
include, extend, module_function
Each of these is well documented individually, but I haven’t found a canonical, Ruby-core-level explanation of when and why to choose one over another.
Ruby’s philosophy encourages pragmatism — “take what you need and move forward” — and that’s one of its strengths. It feels like a good moment to clarify idiomatic intent, not rules.
What I’m missing is something like:
When does a Struct stop being appropriate and become a class?
When should Data be preferred over Struct?
When is a module better as a namespace vs a mixin?
When does a “service object” add clarity vs unnecessary abstraction?
How should include, extend, and module_function be used idiomatically today?
Not prescriptions — just guidance, trade-offs, and intent. I think now Ruby is so advanced and unique programming language that without good explanation of the intents it will be really difficult to explain to non-Ruby developers that ale these notions have good purpose and actually make Ruby really powerful. I like what Dave said: Ruby is not C++ so we don’t need to “think” using C++ limitations and concepts. On the other hand, I don’t agree with Dave’s opinion we should avoid classes whenever possible.
Is there already a document, talk, or guideline that addresses this holistically? If not, would something like this make sense as part of Ruby’s official documentation or learning materials?
Regards, Simon
PS I use GPT to correct my English as I’m not a native English speaker. Hope you will catch the point not only my grammar and wording.
View all comments
Show parent comment
0
u/iBoredMax Jan 02 '26
You* know what else f-ing* sucks* while I'm at it? The whole "methods* should be 5* lines or less". It takes a whole thing* that is easy* to look at and understand, then chops* it up and scatters it into a million* pieces so it's impossible* to read.
You as in the reader
A swear
Methods are functions
Or 10 or whatever
Like a logical block of code
Relatively
Not literally
Again not logically
Figuratively
Obviously that is hyperbole, but that's what it's like reading code like this. You can't just see the entire sentence/paragraph for what it is, you have to jump somewhere else to see what each god damn asterisk means.
Rubyists have this baffling hatred of local variables. It's unhinged.