Skip to content

Instantly share code, notes, and snippets.

@tjstankus
Last active Oct 26, 2015
Embed
What would you like to do?
Functional Ruby
# - Reusable, immutable objects
# - Inject dependencies in constructor
class UserQuery
attr_reader :query
def initialize(query)
@query = query
end
def with(query)
self.class.new(query)
end
def call
query.execute
end
end
# `PersistPerson` is bound the the interface of user_repository, which is better
# than being bound to, say, the hardcoded class name.
class PersistPerson
attr_reader :user_repository
def initialize(user_repository)
@user_repository = user_repository
end
def call(person)
user_repostiory.save(person)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment