@@ -1060,48 +1060,46 @@ rb_ary_s_new(int argc, VALUE *argv, VALUE klass)
1060
1060
* call-seq:
1061
1061
* Array.new -> new_empty_array
1062
1062
* Array.new(array) -> new_array
1063
- * Array.new(size) -> new_array
1064
- * Array.new(size, default_value) -> new_array
1065
- * Array.new(size) {|index| ... } -> new_array
1063
+ * Array.new(size, default_value = nil) -> new_array
1064
+ * Array.new(size = 0) {|index| ... } -> new_array
1066
1065
*
1067
- * Returns a new +Array+.
1066
+ * Returns a new +Array+ object .
1068
1067
*
1069
- * With no block and no arguments, returns a new empty +Array+ object.
1068
+ * - With no block given:
1070
1069
*
1071
- * With no block and a single +Array+ argument +array+ ,
1072
- * returns a new +Array+ formed from + array+ :
1070
+ * - With no argument given ,
1071
+ * returns a new empty array:
1073
1072
*
1074
- * a = Array.new([:foo, 'bar', 2])
1075
- * a.class # => Array
1076
- * a # => [:foo, "bar", 2]
1073
+ * Array.new # => []
1077
1074
*
1078
- * With no block and a single Integer argument +size+,
1079
- * returns a new +Array+ of the given size
1080
- * whose elements are all +nil+:
1075
+ * - With argument +array+ given,
1076
+ * returns a new array containing the elements of +array+:
1081
1077
*
1082
- * a = Array.new(3)
1083
- * a # => [nil, nil, nil]
1078
+ * Array.new([:foo, 'bar', 2]) # => [:foo, "bar", 2]
1084
1079
*
1085
- * With no block and arguments +size+ and +default_value+ ,
1086
- * returns an +Array+ of the given size ;
1087
- * each element is that same +default_value+:
1080
+ * - With numeric argument +size+ given ,
1081
+ * returns a new array containing +size+ instances of the given +default_value+ ;
1082
+ * all elements are the _same_ object +default_value+:
1088
1083
*
1089
- * a = Array.new(3, 'x')
1090
- * a # => ['x', 'x', 'x']
1084
+ * Array.new(3) # => [nil, nil, nil]
1085
+ * Array.new(0) # => []
1086
+ * o = Object.new # => #<Object:0x0000013a6534a170>
1087
+ * Array.new(2, o) # => [#<Object:0x0000013a6534a170>, #<Object:0x0000013a6534a170>]
1088
+ * Array.new(0, o) # => []
1089
+ * Array.new(-1) # Raises ArgumentError (negative array size).
1091
1090
*
1092
- * With a block and argument +size+ ,
1093
- * returns an +Array+ of the given size;
1094
- * the block is called with each successive integer +index+;
1095
- * the element for that +index+ is the return value from the block:
1091
+ * - With a block given ,
1092
+ * returns an array of the given + size+ ;
1093
+ * calls the block with each +index+ in the range <tt>(0..size-1)</tt> ;
1094
+ * the element at that +index+ is the return value from the block:
1096
1095
*
1097
- * a = Array.new(3) {|index| "Element #{index}" }
1098
- * a # => ["Element 0", "Element 1", "Element 2"]
1096
+ * Array.new(3) {|index| "Element #{index}" } # => ["Element 0", "Element 1", "Element 2"]
1097
+ * Array.new(0) {|index| "Element #{index}" } # => []
1098
+ * Array.new(-1) {|index| "Element #{index}" } # Raises ArgumentError (negative array size).
1099
1099
*
1100
- * Raises ArgumentError if +size+ is negative.
1100
+ * Raises TypeError if the argument is not either an array
1101
+ * or an {integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects]).
1101
1102
*
1102
- * With a block and no argument,
1103
- * or a single argument +0+,
1104
- * ignores the block and returns a new empty +Array+.
1105
1103
*/
1106
1104
1107
1105
static VALUE
0 commit comments