Skip to content

Conversation

@kch
Copy link

@kch kch commented Nov 19, 2025

Returns an enumerator. Matching similar methods in ruby stdlib.

@kch kch changed the title Allow calling each_hash without block Allow calling each, each_hash without block Nov 19, 2025
Copy link
Member

@flavorjones flavorjones left a 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).

Comment on lines 120 to 136
def test_each_enum
called = 0
@result.reset(1, 2)
@result.each.to_a.each { |row| called += 1 }
assert_equal 2, called
end
Copy link
Member

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
  end

Copy link
Author

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.

end

# Required by the Enumerable mixin. Provides an internal iterator over the
# rows of the result set.
Copy link
Member

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!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed. lmk if good.

end

# Provides an internal iterator over the rows of the result set where
# each row is yielded as a hash.
Copy link
Member

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!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed. lmk if good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants