Skip to content

Conversation

@kyanagi
Copy link
Contributor

@kyanagi kyanagi commented Dec 5, 2024

No description provided.

#@#デフォルト値の扱いには注意が必要です( [[trap:Hash]] )

#@since 3.4
capacity を指定すると、指定した要素数に相当するメモリをあらかじめ確保します。
Copy link
Member

Choose a reason for hiding this comment

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

rdoc で

If optional keyword argument capacity is given with a positive integer
value n, initializes the hash with enough capacity to accommodate n
entries without resizing.

という説明になっているように、指定した要素数を格納するのに充分なサイズなので、「指定した要素数に相当するメモリ」という説明だと要素数ぴったりのサイズで追加する予定がないなら全く無駄がないサイズにできる、と誤解してしまいそうです。

@znz znz added the Ruby3.4 label Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants