Service Object Interface

Curated ago by @vaporyhumo

Description

Simple example on how to implement the typical .call interface for plain ruby service objects.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Greeter
  extend ServiceInterface

  attr_reader :name

  def initialize(name)
    @name = name
  end

  private

  def perform
    "Hello #{name}"
  end
end

Just define typical initialization and the #perform method. Don’t forget to extend the interface!