Skip to content

Commit 4d72e8c

Browse files
committed
Merge both single line methods
1 parent ef8deda commit 4d72e8c

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

lib/analyzers/two_fer/analyze.rb

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ def analyze!
3535

3636
# There is one optimal solution for two-fer which needs
3737
# no comments and can just be approved. If we have it, then
38-
# let's just acknowledge it and get out of here.
39-
check_for_optimal_solution!
40-
41-
# We often see solutions that are correct but use different
42-
# string concatenation options (e.g. string#+, String.format, etc)
43-
# We'll approve these but want to leave a comment that introduces
44-
# them to string interpolation in case they don't know about it.
45-
check_for_correct_solution_without_string_interpolaton!
38+
# let's just acknowledge it and get out of here. We also often see
39+
# solutions that are correct but use different # string concatenation
40+
# options (e.g. string#+, String.format, etc). We'll approve these but
41+
# want to leave a comment that introduces them to string interpolation
42+
# in case they don't know about it.
43+
check_for_single_line_solution!
4644

4745
# The most common error in twofer is people using conditionals
4846
# to check where the value passed in is nil, rather than using a default
@@ -87,7 +85,10 @@ def check_method_signature!
8785
disapprove!(:missing_default_param) unless solution.first_paramater_has_default_value?
8886
end
8987

90-
def check_for_optimal_solution!
88+
def check_for_single_line_solution!
89+
return unless solution.default_argument_is_optimal?
90+
return unless solution.one_line_solution?
91+
9192
# The optional solution looks like this:
9293
#
9394
# def self.two_fer(name="you")
@@ -97,23 +98,13 @@ def check_for_optimal_solution!
9798
# The default argument must be 'you', and it must just be a single
9899
# statement using interpolation. Other solutions might be approved
99100
# but this is the only one that we would approve without comment.
100-
101-
return unless solution.default_argument_is_optimal?
102-
return unless solution.one_line_solution?
103-
return unless solution.uses_string_interpolation?
104-
105-
# If the interpolation does not follow this pattern then the student has
106-
# done something weird, so let's get a mentor to look at it
107-
refer_to_mentor! unless solution.string_interpolation_is_correct?
108-
109-
approve_if_implicit_return!
110-
end
111-
112-
def check_for_correct_solution_without_string_interpolaton!
113-
# If we don't have a correct default argument or a one line
114-
# solution then let's just get out of here.
115-
return unless solution.default_argument_is_optimal?
116-
return unless solution.one_line_solution?
101+
if solution.uses_string_interpolation?
102+
if solution.string_interpolation_is_correct?
103+
approve_if_implicit_return!
104+
else
105+
refer_to_mentor!
106+
end
107+
end
117108

118109
# In the case of:
119110
# "One for " + name + ", one for me."

0 commit comments

Comments
 (0)