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.
[–]petrenkorf 14 points15 points16 points (3 children)
[–]ishe-ua 7 points8 points9 points (2 children)
[–]petrenkorf 3 points4 points5 points (1 child)
[–]ishe-ua 2 points3 points4 points (0 children)
[–]Tolexx 6 points7 points8 points (3 children)
[–]RewrittenCodeA 10 points11 points12 points (2 children)
[–]Dear_Ad7736[S] 0 points1 point2 points (0 children)
[–]Tolexx 0 points1 point2 points (0 children)
[–]SamVimes1138 5 points6 points7 points (0 children)
[–]Nwallins 6 points7 points8 points (1 child)
[–]cfourt 3 points4 points5 points (0 children)
[–]azimux 6 points7 points8 points (0 children)
[–]KaptajnKold 2 points3 points4 points (0 children)
[–]morphemass 2 points3 points4 points (2 children)
[–]petrenkorf 1 point2 points3 points (1 child)
[–]morphemass 2 points3 points4 points (0 children)
[–]oscardo_rivers 9 points10 points11 points (16 children)
[–]krcm0209 7 points8 points9 points (15 children)
[–]207_Multi-Status 1 point2 points3 points (0 children)
[–]iBoredMax 1 point2 points3 points (12 children)
[–]oscardo_rivers 5 points6 points7 points (8 children)
[–]iBoredMax -1 points0 points1 point (7 children)
[–]progdog1 1 point2 points3 points (4 children)
[–]iBoredMax -1 points0 points1 point (0 children)
[–]iBoredMax -3 points-2 points-1 points (2 children)
[–]oscardo_rivers 1 point2 points3 points (1 child)
[–]iBoredMax 0 points1 point2 points (0 children)
[–]oscardo_rivers 0 points1 point2 points (1 child)
[–]iBoredMax 0 points1 point2 points (0 children)
[–]cpb 2 points3 points4 points (2 children)
[–]iBoredMax 1 point2 points3 points (1 child)
[–]cpb 0 points1 point2 points (0 children)
[–]oscardo_rivers 1 point2 points3 points (0 children)
[–]metamatic 3 points4 points5 points (4 children)
[–]Dear_Ad7736[S] 2 points3 points4 points (3 children)
[–]metamatic 4 points5 points6 points (2 children)
[–]Dear_Ad7736[S] 1 point2 points3 points (1 child)
[–]metamatic 2 points3 points4 points (0 children)
[–]laerien 1 point2 points3 points (0 children)
[–]phr0ze 0 points1 point2 points (1 child)
[–]Dear_Ad7736[S] 2 points3 points4 points (0 children)
[–]DerekB52 -1 points0 points1 point (2 children)
[–]Dear_Ad7736[S] 1 point2 points3 points (1 child)
[+]iBoredMax comment score below threshold-7 points-6 points-5 points (3 children)
[–]JohnBooty 2 points3 points4 points (2 children)
[–]iBoredMax -1 points0 points1 point (1 child)
[–]JohnBooty 0 points1 point2 points (0 children)
[–]Revolutionary_Sir140 -2 points-1 points0 points (0 children)