In Ruby people like to make things objects so you can do all the cute Ruby magic stuff like mixins for sharing code. Many Ruby programmers treat a method/function longer than 10 lines as a code smell; I think this is harmful but the opinion was common. Ruby had very very nice OO stuff and kinda shrug closure handling so, why not?
I always smile when I see stuff like this, objects can be implemented with closures, here we have closures re-implemented with objects. Does ruby not have some native thing for this?
This is not quite the same thing as closures, although lots of example in this article are closure-adjacent or using them directly. It’s more about shining a light on an OOP pattern that is basically adding more boilerplate than a functional style would.
Ruby’s Proc is a first-class function and closure, as are Lambda and method blocks (since they are built on Proc). This is why to-procable interfaces are mentioned.
Why would you use a ThingDoer rather than a closure?
serialization is about the only real answer
In Ruby people like to make things objects so you can do all the cute Ruby magic stuff like mixins for sharing code. Many Ruby programmers treat a method/function longer than 10 lines as a code smell; I think this is harmful but the opinion was common. Ruby had very very nice OO stuff and kinda shrug closure handling so, why not?
Ruby code heavily uses closures, but they are not magic. There are all sorts of reasons you would want an object instead.
I always smile when I see stuff like this, objects can be implemented with closures, here we have closures re-implemented with objects. Does ruby not have some native thing for this?
This is not quite the same thing as closures, although lots of example in this article are closure-adjacent or using them directly. It’s more about shining a light on an OOP pattern that is basically adding more boilerplate than a functional style would.
Ruby’s Proc is a first-class function and closure, as are Lambda and method blocks (since they are built on Proc). This is why to-procable interfaces are mentioned.