-
Notifications
You must be signed in to change notification settings - Fork 210
Allow calling each, each_hash without block #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
flavorjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR! This is a nice quality-of-life improvement. I have just a couple of comments about the test coverage (which I have been trying to improve with every PR).
| def test_each_enum | ||
| called = 0 | ||
| @result.reset(1, 2) | ||
| @result.each.to_a.each { |row| called += 1 } | ||
| assert_equal 2, called | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this test to also assert that the .each returns an Enumerator object. I'd also like a similar test for .each_hash, something like:
def test_each_enum
@result.reset(1, 2)
enum = @result.each
assert_instance_of Enumerator, enum
assert_equal 2, enum.to_a.length
end
def test_each_hash_enum
@result.reset(1, 2)
enum = @result.each_hash
assert_instance_of Enumerator, enum
assert_equal 2, enum.to_a.length
endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah those are fine, just copied over. I also noticed we should return self when no block, so also added tests for that.
lib/sqlite3/resultset.rb
Outdated
| end | ||
|
|
||
| # Required by the Enumerable mixin. Provides an internal iterator over the | ||
| # rows of the result set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the docstring!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed. lmk if good.
lib/sqlite3/resultset.rb
Outdated
| end | ||
|
|
||
| # Provides an internal iterator over the rows of the result set where | ||
| # each row is yielded as a hash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the docstring!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed. lmk if good.
Returns an enumerator. Matching similar methods in ruby stdlib.