Skip to content

Conversation

@hayat01sh1da
Copy link
Owner

@hayat01sh1da hayat01sh1da commented Dec 30, 2025

Summary

When the receiver is one of Array, Hash or String, there is basically no difference in terms of return value which represents the number of elements.
However, if it's of Integer, it returns the number of bytes in the machine representation of self; the value is system-dependent.
It may cause unexpected behaviours, so it should be replaced with #length because Integer#length raises NoMethodError.

Ref. https://docs.ruby-lang.org/en/master/Integer.html#method-i-size

@hayat01sh1da hayat01sh1da self-assigned this Dec 30, 2025
Copy link
Owner Author

@hayat01sh1da hayat01sh1da left a comment

Choose a reason for hiding this comment

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

LGTM

@hayat01sh1da hayat01sh1da merged commit 0da7693 into master Dec 30, 2025
6 checks passed
@hayat01sh1da hayat01sh1da deleted the hayat01sh1da/ruby/replace-size-with-length-to-prevent-unexpected-behaviour-in-the-case-of-integer branch December 30, 2025 09:27
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