Project

General

Profile

Bug #5344 ยป 0001-Clarified-Array.new-documentation.patch

henry.maddocks (Henry Maddocks), 09/21/2011 09:14 AM

View differences:

array.c
507 507
 *     Array.new(size) {|index| block }
508 508
 *
509 509
 *  Returns a new array. In the first form, the new array is
510
 *  empty. In the second it is created with _size_ copies of _obj_
511
 *  (that is, _size_ references to the same
512
 *  _obj_). The third form creates a copy of the array
510
 *  empty, or it is created with _size_ copies of _obj_ (that is,
511
 *  _size_ references to the same _obj_). 
512
 *  The second form creates a copy of the array
513 513
 *  passed as a parameter (the array is generated by calling
514 514
 *  to_ary  on the parameter). In the last form, an array
515 515
 *  of the given size is created. Each element in this array is
516 516
 *  calculated by passing the element's index to the given block and
517 517
 *  storing the return value.
518 518
 *
519
 *     Array.new
520
 *     Array.new(2)
521
 *     Array.new(5, "A")
519
 *     Array.new                         #=> [] 
520
 *     Array.new(2)                      #=> [nil, nil] 
521
 *     Array.new(5, "A")                 #=> ["A", "A", "A", "A", "A"] 
522 522
 *
523 523
 *     # only one copy of the object is created
524
 *     a = Array.new(2, Hash.new)
525
 *     a[0]['cat'] = 'feline'
526
 *     a
527
 *     a[1]['cat'] = 'Felix'
528
 *     a
524
 *     a = Array.new(2, Hash.new)        #=> [{}, {}] 
525
 *     a[0]['cat'] = 'feline'            #=> "feline" 
526
 *     a                                 #=> [{"cat"=>"feline"}, {"cat"=>"feline"}] 
527
 *     a[1]['cat'] = 'Felix'             #=> "Felix" 
528
 *     a                                 #=> [{"cat"=>"Felix"}, {"cat"=>"Felix"}] 
529 529
 *
530 530
 *     # here multiple copies are created
531
 *     a = Array.new(2) { Hash.new }
532
 *     a[0]['cat'] = 'feline'
533
 *     a
531
 *     a = Array.new(2) { Hash.new }     #=> [{}, {}] 
532
 *     a[0]['cat'] = 'feline'            #=> "feline" 
533
 *     a                                 #=> [{"cat"=>"feline"}, {}]
534 534
 *
535
 *     squares = Array.new(5) {|i| i*i}
536
 *     squares
537
 *
538
 *     copy = Array.new(squares)
535
 *     squares = Array.new(5) {|i| i*i}  #=> [0, 1, 4, 9, 16] 
536
 *     
537
 *     copy = Array.new(squares)         #=> [0, 1, 4, 9, 16] 
539 538
 */
540 539

  
541 540
static VALUE
542
-