aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authorsonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 23:44:15 +0000
committersonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 23:44:15 +0000
commitf434b30d0670417ee0b9114ea0368130fda7c394 (patch)
treed1feee224013a03c9861b86ea3c82a6a4eac3066 /object.c
parent39db0b80683e951d47995f08c5306776e2d3c13a (diff)
downloadruby-f434b30d0670417ee0b9114ea0368130fda7c394.tar.gz
* object.c: Improve documentation of Kernel#Array
Array(arg) does more than just call to_ary or to_a on the argument. It also falls back to returning [arg] if neither method is available. This patch extends the description and adds a few examples of how it handles common types of arguments, including an integer (which does not implement to_ary or to_a). Extend Kernel#Array doc to mention TypeError patched by ragesoss (Sage Ross) [fix GH-1663] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/object.c b/object.c
index 7f5e89f6bc..ba43eaf70c 100644
--- a/object.c
+++ b/object.c
@@ -3609,8 +3609,17 @@ rb_Array(VALUE val)
* Returns +arg+ as an Array.
*
* First tries to call <code>to_ary</code> on +arg+, then <code>to_a</code>.
+ * If +arg+ does not respond to <code>to_ary</code> or <code>to_a</code>,
+ * returns an Array of length 1 containing +arg+.
*
- * Array(1..5) #=> [1, 2, 3, 4, 5]
+ * If <code>to_ary</code> or <code>to_a</code> returns something other than
+ * an Array, raises a <code>TypeError</code>.
+ *
+ * Array(["a", "b"]) #=> ["a", "b"]
+ * Array(1..5) #=> [1, 2, 3, 4, 5]
+ * Array(key: :value) #=> [[:key, :value]]
+ * Array(nil) #=> []
+ * Array(1) #=> [1]
*/
static VALUE