Skip to content

Instantly share code, notes, and snippets.

@cpb cpb/example.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.