-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Journey::Routes #8783
Refactor Journey::Routes #8783
Conversation
goshacmd
commented
Jan 6, 2013
- prefer do-end for multiline blocks
- prefer or-equals over returns with checks
I really don't like |
@rafaelfranca ok, reverted it. |
end | ||
|
||
def ast | ||
return @ast if @ast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change the behavior since if @ast
is present it still will check if partitioned_routes.first
is blank. The before code doesn't behave this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see if @ast
is set anywhere besides this method. Therefore, if partitioned_routes.first.empty?
ever returns true, @ast
won't get assigned. I think it is safe to make this change. Also, tests do pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you didn't get. Before this change in the first call all the method body is called, and in the second call only the first line. So partitioned_routes.first.empty?
is only called on the first call.
After this change partitioned_routes.first.empty?
is called in every call of this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, I think it can be refactored as follows:
@ast ||= begin
asts = partitioned_routes.first.map(&:ast)
Nodes::Or.new(asts) unless asts.empty?
end
So that, if partitioned_routes.first
is empty, partitioned_routes.first.map(&:ast)
would also be empty. Therefore Nodes::Or.new(asts) unless asts.empty?
will set @ast
to nil
in case it's empty, and to Nodes::Or
otherwise. That behavior is completely identical to the original one.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed that & rebased.
* prefer do-end for multiline blocks * prefer or-equals over returns with checks
Thanks. |