Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created November 9, 2017 15:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ka8725/27321acc3d22a7d954505d974e414a9e to your computer and use it in GitHub Desktop.
Save ka8725/27321acc3d22a7d954505d974e414a9e to your computer and use it in GitHub Desktop.
class BaseService
def self.inherited(superclass)
Object.send(:define_method, superclass.name) do |*params|
superclass.new(*params).call
end
end
end
class UnfollowObjectService < BaseService
def initialize(object, user)
@object = object
@user = user
end
def call
Following.where(object: @object, follower: @user).update_all(deleted_at: Time.current)
end
end
UnfollowObjectService(Tweet.find(1), User.find(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment