File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class Analyze < ExerciseAnalyzer
3
3
include Mandate
4
4
5
5
def analyze!
6
- if solution . uses_method_chain? || solution . uses_scan?
6
+ if solution . uses_method_chain? || solution . uses_scan? || solution . uses_split?
7
7
self . status = :approve
8
8
9
9
raise FinishedFlowControlException
Original file line number Diff line number Diff line change @@ -39,6 +39,34 @@ def uses_scan?
39
39
all? { |node , i | node_matches? ( node , matchers [ i ] ) }
40
40
end
41
41
42
+ def uses_split?
43
+ matchers = [
44
+ {
45
+ method_name : :upcase ,
46
+ } ,
47
+ {
48
+ method_name : :join ,
49
+ chained? : true
50
+ } ,
51
+ {
52
+ method_name : :map ,
53
+ chained? : true ,
54
+ arguments : [ { to_ast : s ( :block_pass , s ( :sym , :chr ) ) } ]
55
+ } ,
56
+ {
57
+ method_name : :split ,
58
+ receiver : s ( :lvar , :words ) ,
59
+ arguments : [ { type : :regexp } ]
60
+ }
61
+ ]
62
+
63
+ target_method .
64
+ body .
65
+ each_node ( :send ) .
66
+ with_index .
67
+ all? { |node , i | node_matches? ( node , matchers [ i ] ) }
68
+ end
69
+
42
70
private
43
71
memoize
44
72
def target_method
Original file line number Diff line number Diff line change @@ -27,4 +27,17 @@ def self.abbreviate(words)
27
27
assert_equal :approve , results [ :status ]
28
28
assert_equal [ ] , results [ :comments ]
29
29
end
30
+
31
+ def test_split_with_any_regex_passes
32
+ source = %q{
33
+ class Acronym
34
+ def self.abbreviate(words)
35
+ words.split(/[ -]/).map(&:chr).join.upcase
36
+ end
37
+ end
38
+ }
39
+ results = Acronym ::Analyze . ( source )
40
+ assert_equal :approve , results [ :status ]
41
+ assert_equal [ ] , results [ :comments ]
42
+ end
30
43
end
You can’t perform that action at this time.
0 commit comments