Created
February 12, 2016 20:40
-
-
Save adelevie/7809bb86b8e1e4f761b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def complete_and_successful | |
relation = delivery_deadline_expired(@relation) | |
relation = delivered(relation) | |
relation = accepted(relation) | |
relation = cap_submitted(relation) | |
relation = paid(relation) | |
relation | |
end |
If these could properly be considered attributes or features of Relation
(and they do read that way), then refactor them to make them instance methods which return self
. Then you can do:
def complete_and_successful
@relation
.delivery_deadline_expired
.delivered
.accepted
.cap_submitted
.paid
end
You could also do this without refactoring the functions into methods by using .tap
:
def complete_and_successful
@relation
.tap { |r| delivery_deadline_expired(r) }
.tap { |r| delivered(r) }
.tap { |r| accepted(r) }
.tap { |r| cap_submitted(r) }
.tap { |r| paid(r) }
end
@krues8dr, you've been doing a lot of javascript or python programming. 😄 In Ruby it'd look like this:
def complete_and_successful
[:delivery_deadline_expired, :delivered, :accepted, :cap_submitted, :paid].inject(@relation) do |obj, method|
obj.send(method)
end
end
@dogweather Ugh, you're right. Language switching on a Friday afternoon. :) I definitely agree that the chained version is much nicer!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's been a while since I've done this sort of thing, but would this work?