Skip to content

Commit 0aa02b3

Browse files
committed
support calling each_hash without block. returns enumerator
1 parent 4bf2ce7 commit 0aa02b3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/sqlite3/resultset.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def each
5454
# Provides an internal iterator over the rows of the result set where
5555
# each row is yielded as a hash.
5656
def each_hash
57+
return enum_for(__method__) unless block_given?
5758
while (node = next_hash)
5859
yield node
5960
end

test/test_result_set.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def test_each_hash
2424
assert_equal list[hash["a"] - 1], hash["b"]
2525
end
2626
rs.close
27+
28+
rs = @db.prepare("select * from foo").execute
29+
rs.each_hash.to_a do |hash|
30+
assert_equal list[hash["a"] - 1], hash["b"]
31+
end
32+
rs.close
2733
end
2834

2935
def test_next_hash

0 commit comments

Comments
 (0)