Skip to content

Commit 07d4f5c

Browse files
committed
Clean up iteration of NodeList elements
1 parent f914ca3 commit 07d4f5c

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

lib/rbs/ffi/parser.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,30 @@ class NodeList < FFI::Struct
130130

131131
def to_a
132132
ary = []
133-
head = self.safe_get(:head)
134-
while head
135-
ary << head.safe_get(:node)
136-
nxt = head[:next]
137-
break if nxt.address == 0
138-
head = NodeListNode.new(nxt)
133+
each do |node|
134+
ary << node
139135
end
140136
ary
141137
end
142138

143139
def inspect
144140
str = +"#<NodeList ["
145-
head = self.safe_get(:head)
146-
while head
141+
each do |node|
147142
str << head.inspect
148-
nxt = head[:next]
149-
break if nxt.address == 0
150-
head = NodeListNode.new(nxt)
151143
end
152144
str << "]>"
153145
str
154146
end
147+
148+
def each
149+
node = self.safe_get(:head)
150+
while node
151+
yield node
152+
nxt = node[:next]
153+
break if nxt.address == 0
154+
node = NodeListNode.new(nxt)
155+
end
156+
end
155157
end
156158

157159
class Signature < FFI::Struct

0 commit comments

Comments
 (0)