3 ms·
Here is common use case I use for this in my Rails apps: This is the most common way I use it: class ApplicationService def call raise NotIm
by bradly 3y ago
Here is common use case I use for this in my Rails apps:
This is the most common way I use it:
class ApplicationService
def call
raise NotImplementedError
end
def self.call(...)
new(...).call
end
end
class MyService < ApplicationService
def call(service_specific_arg: 123)
#...
end
end
- viralpraxis 3y agoI’ve been using the same structure for years :) But I prefer to replace ‘raise NotImplementedError’ with ´raise “Not Implemeneted”’ because that exception has different semantics (method unavailability on the current platform)
- prognostikos 3y agoI also avoid `NotImplementedError` as it inherits from `Error` instead of `StandardError`. This can bring down services like job queue processors that rescue `StandardError`.
- still_grokking 3y agoWhat is this code good for? I can understand what it does but I don't get the intend behind that. (I'm not a Ruby programmer, so maybe I miss something "obvious")