Open
Conversation
第一引数posが負の値の場合String#insertとString#[]=は異なる操作を行う ``` # posが正の場合String#insertとString#[]=は同じ操作を行う str = 'foo'; str.insert(1, 'bar') # => "fbaroo" str = 'foo'; str[1, 0] = 'bar'; str # => "fbaroo" # posが負の場合String#insertとString#[]=は異なる操作を行う str = 'foo'; str.insert(-1, 'bar') # => "foobar" str = 'foo'; str[-1, 0] = 'bar'; str # => "fobaro" ```
znz
requested changes
Jun 10, 2025
| 'foo'.insert(-2, 'bar') # => "fobaro" | ||
| #@end | ||
|
|
||
| @see [[m:String#[]=]] |
Member
There was a problem hiding this comment.
用途によって使いわけられるので、see は消さなくても良いと思います。
Comment on lines
+1817
to
1826
| 文字列 other を self に挿入して self を返します。 | ||
| pos が正の場合、other を開始インデックスに挿入します。 | ||
|
|
||
| #@samplecode 例 | ||
| 'foo'.insert(1, 'bar') # => "fbaroo" | ||
| #@end | ||
|
|
||
| pos が負の場合、self の末尾から逆方向に数えて pos+1 (self[index] の後) に other を挿入します。 | ||
| pos 番目の文字の直前に文字列 other を挿入します。 | ||
| self[pos, 0] = other と同じ操作です。 |
Member
There was a problem hiding this comment.
最初の段落はメソッドの要約になるので、pos が正の場合と負の場合の説明は長くなるので入れない方がいいかなと思いました。
Suggested change
| 文字列 other を self に挿入して self を返します。 | |
| pos が正の場合、other を開始インデックスに挿入します。 | |
| #@samplecode 例 | |
| 'foo'.insert(1, 'bar') # => "fbaroo" | |
| #@end | |
| pos が負の場合、self の末尾から逆方向に数えて pos+1 (self[index] の後) に other を挿入します。 | |
| pos 番目の文字の直前に文字列 other を挿入します。 | |
| self[pos, 0] = other と同じ操作です。 | |
| 文字列 other を self に挿入して self を返します。 | |
| pos が正の場合、pos 番目の文字の直前に文字列 other を挿入します。 | |
| self[pos, 0] = other と同じ操作です。 | |
| #@samplecode 例 | |
| 'foo'.insert(1, 'bar') # => "fbaroo" | |
| #@end | |
| pos が負の場合、self の末尾から逆方向に数えて pos+1 (self[index] の後) に other を挿入します。 |
| str = "foobaz" | ||
| str.insert(3, "bar") | ||
| p str # => "foobarbaz" | ||
| 'foo'.insert(-2, 'bar') # => "fobaro" |
Member
There was a problem hiding this comment.
例は pull request の説明に書いてくれたものを全部書いておいてくれると良さそうです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
第一引数posが負の値の場合String#insertとString#[]=は異なる操作を行うため、正の場合と負の場合に分けた説明にしました。