From 2adcc0b8faa27d9ffdea21403fbf97ec2f3fea66 Mon Sep 17 00:00:00 2001 From: sonots Date: Sat, 21 Oct 2017 23:44:15 +0000 Subject: * 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 --- object.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'object.c') 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 to_ary on +arg+, then to_a. + * If +arg+ does not respond to to_ary or to_a, + * returns an Array of length 1 containing +arg+. * - * Array(1..5) #=> [1, 2, 3, 4, 5] + * If to_ary or to_a returns something other than + * an Array, raises a TypeError. + * + * 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 -- cgit v1.2.3