symbol.patch

sho-h (Sho Hashimoto), 12/18/2009 12:01 am

Download (4.4 kB)

refm/api/src/_builtin/Symbol (working copy)
183 183
--- next -> Symbol
184 184
#@todo
185 185

  
186
シンボルに対応する文字列の「次の」文字列を返します。
187
(self.to_s.next.intern と同じです。)
188

  
189
  :a.next   # -> :b
190
  :foo.next # -> :fop
191

  
186 192
@see [[m:String#succ]]
187 193

  
188
--- <=>(other) -> Integer
194
--- <=>(other) -> -1 | 0 | 1
189 195
#@todo
190 196

  
197
self と other のシンボルに対応する文字列を ASCII コード順で比較して、
198
self が大きい時には正の整数、等しい時には 0、小さい時には負の整数を返し
199
ます。
200

  
201
  p :aaa <=> :xxx  # => -1
202
  p :aaa <=> :aaa  # => 0
203
  p :xxx <=> :aaa  # => 1
204

  
191 205
@see [[m:String#<=>]]
192 206

  
193
--- casecmp(other) -> Integer
207
--- casecmp(other) -> -1 | 0 | 1
194 208
#@todo
195 209

  
210
[[m:Symbol#<=>]] と同様にシンボルに対応する文字列の順序を比較しますが、
211
アルファベットの大文字小文字の違いを無視します。
212

  
213
  p :a <=> :A      # => 1
214
  p :a.casecmp(:A) # => 0
215

  
196 216
@see [[m:String#casecmp]]
197 217

  
198
--- =~(other) -> Integer
218
--- =~(other) -> Integer | nil
219
--- match(other) -> Integer | nil
199 220
#@todo
200 221

  
201
@see [[m:String#=~]]
222
正規表現 other とのマッチを行います。(self.to_s =~ other と同じです。)
202 223

  
203
--- []
204
--- slice
224
マッチが成功すればマッチした位置のインデックスを、そうでなければ nil を返します。
225

  
226
  p :foo =~ /foo/    # => 0
227
  p :foobar =~ /bar/ # => 3
228
  p :foo =~ /bar/    # => nil
229

  
230
@see [[m:String#=~]], [[m:String#match]]
231

  
232
--- [](nth) -> String | nil
233
--- slice(nth) -> String | nil
205 234
#@todo
206 235

  
236
nth 番目の文字を返します。(self.to_s[nth] と同じです。)
237

  
238
  :foo[0] # => "f"
239
  :foo[1] # => "o"
240
  :foo[2] # => "o"
241

  
242
--- [](nth, len) -> String | nil
243
--- slice(nth, len) -> String | nil
244

  
245
nth 番目から長さ len の部分文字列を新しく作って返します。
246
(self.to_s[nth, len] と同じです。)
247

  
248
  :foo[1, 2] # => "oo"
249

  
250
--- [](substr) -> String | nil
251
--- slice(substr) -> String | nil
252

  
253
self が substr を含む場合、一致した文字列を新しく作って返します。
254
(self.to_s[substr] と同じです。)
255

  
256
--- [](regexp, nth = 0) -> String | nil
257
--- slice(regexp, nth = 0) -> String | nil
258

  
259
正規表現 regexp の nth 番目の括弧にマッチする最初の部分文字列を返します。
260
(self.to_s[regexp, nth] と同じです。)
261

  
262
  :foobar[/bar/] # => "bar"
263
  :foobarbaz[/(ba.)(ba.)/, 1] # => "bar"
264
  :foobarbaz[/(ba.)(ba.)/, 2] # => "baz"
265

  
266
--- [](range) -> String | nil
267
--- slice(range) -> String | nil
268

  
269
rangeで指定したインデックスの範囲に含まれる部分文字列を返します。
270
(self.to_s[range] と同じです。)
271

  
272
  :foo[0..1] # => "fo"
273

  
207 274
@see [[m:String#[] ]], [[m:String#slice]]
208 275

  
209 276
--- length -> Integer
210 277
--- size -> Integer
211 278
#@todo
212 279

  
280
シンボルに対応する文字列の長さを返します。(self.to_s.length と同じです。)
281

  
282
  :foo.length #=> 3
283

  
213 284
@see [[m:String#length]], [[m:String#size]]
214 285

  
215 286
--- empty? -> bool
216 287
#@todo
217 288

  
218
@see [[m:String#empty?]]
289
self が :"" (length が 0 のシンボル)かどうかを返します。
219 290

  
220
--- match
221
#@todo
291
  :"".empty?  #=> true
292
  :foo.empty? #=> false
222 293

  
223
@see [[m:String#match]]
294
@see [[m:String#empty?]]
224 295

  
225 296
--- upcase -> Symbol
226 297
#@todo
227 298

  
299
小文字を大文字に変換したシンボルを返します。
300
(self.to_s.upcase.intern と同じです。)
301

  
302
  :foo.upcase #=> :FOO
303

  
228 304
@see [[m:String#upcase]]
229 305

  
230 306
--- downcase -> Symbol
231 307
#@todo
232 308

  
309
大文字を小文字に変換したシンボルを返します。
310
(self.to_s.downcase.intern と同じです。)
311

  
312
  :FOO.downcase #=> :foo
313

  
233 314
@see [[m:String#downcase]]
234 315

  
235 316
--- capitalize -> Symbol
236 317
#@todo
237 318

  
319
シンボルに対応する文字列の先頭の文字を大文字に、残りを小文字に変更した
320
シンボルを返します。(self.to_s.capitalize.intern と同じです。)
321

  
322
  :foobar.capitalize     #=> :Foobar
323
  :fooBar.capitalize     #=> :Foobar
324
  :FOOBAR.capitalize     #=> :Foobar
325
  :"foobar--".capitalize # => "Foobar--"
326

  
238 327
@see [[m:String#capitalize]]
239 328

  
240 329
--- swapcase -> Symbol
241 330
#@todo
242 331

  
332
'A' から 'Z' までのアルファベット大文字を小文字に、'a' から 'z' までの
333
アルファベット小文字を大文字に変更したシンボルを返します。
334
(self.to_s.swapcase.intern と同じです。)
335

  
336
  p :ABCxyz.swapcase   # => :abcXYZ
337
  p :Access.swapcase   # => :aCCESS
338

  
243 339
@see [[m:String#swapcase]]
244 340

  
245 341
--- encoding   -> Encoding
246 342
#@todo
247 343

  
344
シンボルに対応する文字列のエンコーディング情報を表現した Encoding オブ
345
ジェクトを返します。
346

  
248 347
@see [[m:String#encoding]]
249 348

  
250 349
#@end
......
252 351
--- inspect    -> String
253 352
#@todo
254 353

  
255
Returns the representation of sym as a symbol literal.
354
自身を人間に読みやすい文字列にして返します。
256 355

  
257
   :fred.inspect   #=> ":fred"
356
  :fred.inspect   #=> ":fred"