File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,18 @@ def compare_and_clear(head)
64
64
compare_and_set_head head , EMPTY
65
65
end
66
66
67
+ include Enumerable
68
+
69
+ def each ( head = nil )
70
+ return to_enum ( :each , head ) unless block_given?
71
+ it = head || peek
72
+ until it . equal? ( EMPTY )
73
+ yield it . value
74
+ it = it . next_node
75
+ end
76
+ self
77
+ end
78
+
67
79
def clear
68
80
while true
69
81
current_head = head
@@ -72,16 +84,15 @@ def clear
72
84
end
73
85
end
74
86
75
- include Enumerable
76
-
77
- def each
78
- return to_enum unless block_given?
79
- it = peek
80
- until it . equal? ( EMPTY )
81
- yield it . value
82
- it = it . next_node
87
+ def clear_each ( & block )
88
+ while true
89
+ current_head = head
90
+ return self if current_head == EMPTY
91
+ if compare_and_set_head current_head , EMPTY
92
+ each current_head , & block
93
+ return self
94
+ end
83
95
end
84
- self
85
96
end
86
97
87
98
end
You can’t perform that action at this time.
0 commit comments