Skip to content

Instantly share code, notes, and snippets.

@cpb
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpb/9262581 to your computer and use it in GitHub Desktop.
Save cpb/9262581 to your computer and use it in GitHub Desktop.
replace method with method object
class UserAdder < Struct.new(:user_params, :company_id, :role)
extend FriendlyMethodObject
def initialize(*)
super
# Provide defaults for optional members
self.role ||= :default_role
end
def call
# Proprietary business logic here
end
private
# Put access to non attribute dependencies in private methods
def create_user(params)
end
def company
end
def send_enrollment_email(user)
end
end
module FriendlyMethodObject
def call(by_name = {})
new(*by_name.values_at(members)).call
end
alias_method :perform, :call
def to_proc
proc do |*args|
call(*args)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment