1. 2
  1.  

  2. 1

    This is hands-down my favorite pattern in Ruby, and I use it all the time. I tend to take it further and do two things:

    1. Make the entire class constant a callable, meaning that the method it exposes is always called call.
    2. Name the class like I’d name a function.

    What this means is:

    1. You don’t have to live in the Kingdom of Nouns anymore.
    2. You don’t have to think of a clever name for the method that does the work.
    3. Because the class is a callable, you can treat it like a lambda and use the .() syntax. That makes it look even more like you’re calling a function.

    What that means in practice is that when you want to kick off this class, you will end up saying something like

    CalculatePayroll.(payroll)
    

    instead of

    PayrollCalculator.calculate(payroll)