A module for implementing the Service Object pattern that allows for custom "verbs".
Including CallMe in your class adds a call class method that instantiates an
object of the class using the provided arguments and invokes its call method.
For example:
Thing = Struct.new(:value) do
include CallMe
def call
puts value
end
end
Thing.call(123)
# => "123"If you would prefer a verb other than call, then use
CallMe.with(:your_verb):
Thing = Struct.new(:value) do
include CallMe.with(:say)
def say
puts value
end
end
Thing.say(123)
# => "123"with is aliased to [], so you can use CallMe[:verb] instead of CallMe.with(:verb) if you prefer.
One final note: while the examples all use include, you can also use extend.