Bug #91 [ruby-reference-manual:868]
String#[] が範囲外を指定した場合に nil ではなく空文字を返す
| Status : | Closed | Start : | 05/11/2008 | |
| Priority : | Normal | Due date : | ||
| Assigned to : | taifu kouya | % Done : | 100% |
|
| Category : | doc | |||
| Target version : | - | |||
| reporter : | sheepman |
ruby_version : | ||
Description
"bar"[3,1], 'abcd'[4..2] は全て nil ではなく空文字を返します。
History
06/14/2008 01:03 PM - taifu kouya
- Status changed from Open to Assigned
- Assigned to set to taifu kouya
- % Done changed from 0 to 50
直しました。 C言語の'\0'について書くべきなのかな? Author: kouya Date: 2008-06-14 12:56:31 +0900 New Revision: 2773 Changed: U doctree/trunk/refm/api/src/_builtin/String Log: fix Bug#91[ruby-reference-manual:868]Modified: doctree/trunk/refm/api/src/_builtin/String =================================================================== --- doctree/trunk/refm/api/src/_builtin/String 2008-06-14 03:46:33 UTC (rev 2772) +++ doctree/trunk/refm/api/src/_builtin/String 2008-06-14 03:56:31 UTC (rev 2773) @@ -426,8 +426,8 @@ このメソッドの逆に文字コードから文字列を得るには [[m:Integer#chr]] を使ってください。 ---- [](nth, len) -> String ---- slice(nth, len) -> String +--- [](nth, len) -> String | nil +--- slice(nth, len) -> String | nil nth バイト番目から長さ len バイトの部分文字列を新しく作って返します。 nth が負の場合は文字列の末尾から数えます。 @@ -447,9 +447,10 @@ p str0[-1, 1] #=> "r" p str0[-1, 2] #=> "r" (飽くまでも「右に向かって len バイト」) - p str0[3, 1] #=> nil + p str0[3, 1] #=> "" + p str0[4, 1] #=> nil p str0[-4, 1] #=> nil - str1 = str[0, 2] # (str0の「一部」をstr1とする) + str1 = str0[0, 2] # (str0の「一部」をstr1とする) p str1 #=> "ba" str1[0] = "XYZ" p str1 #=> "XYZa" (str1の内容が破壊的に変更された)
06/14/2008 01:03 PM - Anonymous
Issue#91has been updated by taifu kouya. Status changed from Open to Assigned Assigned to set to taifu kouya % Done changed from 0 to 50 直しました。 C言語の'\0'について書くべきなのかな? Author: kouya Date: 2008-06-14 12:56:31 +0900 New Revision: 2773 Changed: U doctree/trunk/refm/api/src/_builtin/String Log: fix Bug#91[ruby-reference-manual:868]Modified: doctree/trunk/refm/api/src/_builtin/String =================================================================== --- doctree/trunk/refm/api/src/_builtin/String 2008-06-14 03:46:33 UTC (rev 2772) +++ doctree/trunk/refm/api/src/_builtin/String 2008-06-14 03:56:31 UTC (rev 2773) @@ -426,8 +426,8 @@ このメソッドの逆に文字コードから文字列を得るには [[m:Integer#chr]] を使ってください。 ---- [](nth, len) -> String ---- slice(nth, len) -> String +--- [](nth, len) -> String | nil +--- slice(nth, len) -> String | nil nth バイト番目から長さ len バイトの部分文字列を新しく作って返します。 nth が負の場合は文字列の末尾から数えます。 @@ -447,9 +447,10 @@ p str0[-1, 1] #=> "r" p str0[-1, 2] #=> "r" (飽くまでも「右に向かって len バイト」) - p str0[3, 1] #=> nil + p str0[3, 1] #=> "" + p str0[4, 1] #=> nil p str0[-4, 1] #=> nil - str1 = str[0, 2] # (str0の「一部」をstr1とする) + str1 = str0[0, 2] # (str0の「一部」をstr1とする) p str1 #=> "ba" str1[0] = "XYZ" p str1 #=> "XYZa" (str1の内容が破壊的に変更された) ---------------------------------------- Bug#91: String#[] が範囲外を指定した場合に nil ではなく空文字を返す http://redmine.ruby-lang.org/issues/show/91 Author: Ken DATE Status: Assigned Priority: Normal Assigned to: taifu kouya Category: doc Target version: reporter: sheepman ruby_version: "bar"[3,1], 'abcd'[4..2] は全て nil ではなく空文字を返します。 ---------------------------------------- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://redmine.ruby-lang.org/my/account