benoit, French
@benoit@ruby.social avatar

I'm not a huge fan of this...

I don't know.

tekin,
@tekin@ruby.social avatar

@benoit I am also generally not a fan but a colleague had a good heuristic for when this pattern can make sense: when the class itself is a single verb and the only thing it does is carry out that action with call

JonRowe,
@JonRowe@fosstodon.org avatar

@tekin @benoit +1 this, if you want to pass a module as a callable this is ok [but why do you need a module as a callable], the instance then is a bit weird but if you need to make things "private” I guess its... fine

pat, (edited )
@pat@hachyderm.io avatar

@JonRowe @tekin @benoit I must admit this is pattern I use a lot - though using Ruby's ellipsis for argument forwarding - and yes, for classes that perform a single action.

I find it removes needing to think about how to invoke the action (i.e. should it be .create, .save, .send? Less confusion, just always use .call).

And it’s the same interface for invoking procs (a use-case for which .new().call doesn't fit), so I can pass callable objects (proc, class, or instance) as arguments.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • thenastyranch
  • ngwrru68w68
  • magazineikmin
  • khanakhh
  • rosin
  • mdbf
  • Youngstown
  • slotface
  • everett
  • cisconetworking
  • kavyap
  • tacticalgear
  • InstantRegret
  • JUstTest
  • Durango
  • osvaldo12
  • ethstaker
  • modclub
  • GTA5RPClips
  • Leos
  • cubers
  • tester
  • normalnudes
  • megavids
  • provamag3
  • anitta
  • lostlight
  • All magazines