From 2bbd60adbf75c33e9ff5fad1a00c390ee2e8603e Mon Sep 17 00:00:00 2001 From: Henry Maddocks Date: Wed, 21 Sep 2011 11:33:36 +1200 Subject: [PATCH] Clarified Array.new documentation Main comment didn't match the examples. Show output of the code examples. --- array.c | 35 +++++++++++++++++------------------ 1 files changed, 17 insertions(+), 18 deletions(-) diff --git a/array.c b/array.c index 8caad66..03c54d6 100644 --- a/array.c +++ b/array.c @@ -507,35 +507,34 @@ rb_ary_s_try_convert(VALUE dummy, VALUE ary) * Array.new(size) {|index| block } * * Returns a new array. In the first form, the new array is - * empty. In the second it is created with _size_ copies of _obj_ - * (that is, _size_ references to the same - * _obj_). The third form creates a copy of the array + * empty, or it is created with _size_ copies of _obj_ (that is, + * _size_ references to the same _obj_). + * The second form creates a copy of the array * passed as a parameter (the array is generated by calling * to_ary on the parameter). In the last form, an array * of the given size is created. Each element in this array is * calculated by passing the element's index to the given block and * storing the return value. * - * Array.new - * Array.new(2) - * Array.new(5, "A") + * Array.new #=> [] + * Array.new(2) #=> [nil, nil] + * Array.new(5, "A") #=> ["A", "A", "A", "A", "A"] * * # only one copy of the object is created - * a = Array.new(2, Hash.new) - * a[0]['cat'] = 'feline' - * a - * a[1]['cat'] = 'Felix' - * a + * a = Array.new(2, Hash.new) #=> [{}, {}] + * a[0]['cat'] = 'feline' #=> "feline" + * a #=> [{"cat"=>"feline"}, {"cat"=>"feline"}] + * a[1]['cat'] = 'Felix' #=> "Felix" + * a #=> [{"cat"=>"Felix"}, {"cat"=>"Felix"}] * * # here multiple copies are created - * a = Array.new(2) { Hash.new } - * a[0]['cat'] = 'feline' - * a + * a = Array.new(2) { Hash.new } #=> [{}, {}] + * a[0]['cat'] = 'feline' #=> "feline" + * a #=> [{"cat"=>"feline"}, {}] * - * squares = Array.new(5) {|i| i*i} - * squares - * - * copy = Array.new(squares) + * squares = Array.new(5) {|i| i*i} #=> [0, 1, 4, 9, 16] + * + * copy = Array.new(squares) #=> [0, 1, 4, 9, 16] */ static VALUE -- 1.7.4.4