Skip to content

Commit c161a01

Browse files
committed
Approve acronym when using scan
1 parent a141dcb commit c161a01

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/analyzers/acronym/analyze.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Analyze < ExerciseAnalyzer
33
include Mandate
44

55
def analyze!
6-
if solution.uses_method_chain?
6+
if solution.uses_method_chain? || solution.uses_scan?
77
self.status = :approve
88

99
raise FinishedFlowControlException

lib/analyzers/acronym/representation.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ def uses_method_chain?
1616
:upcase)
1717
end
1818

19+
def uses_scan?
20+
target_method.body == s(:send,
21+
s(:send,
22+
s(:send,
23+
s(:lvar, :words),
24+
:scan,
25+
s(:regexp, s(:str, "\\b[[:alpha:]]"), s(:regopt))
26+
),
27+
:join),
28+
:upcase)
29+
end
30+
1931
private
2032
memoize
2133
def target_method

test/exercises/acronym_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ def self.abbreviate(words)
1414
assert_equal :approve, results[:status]
1515
assert_equal [], results[:comments]
1616
end
17+
18+
def test_scan_passes
19+
source = %q{
20+
class Acronym
21+
def self.abbreviate(words)
22+
words.scan(/\b[[:alpha:]]/).join.upcase
23+
end
24+
end
25+
}
26+
results = Acronym::Analyze.(source)
27+
assert_equal :approve, results[:status]
28+
assert_equal [], results[:comments]
29+
end
1730
end

0 commit comments

Comments
 (0)