ruby-changes:48212
From: sonots <ko1@a...>
Date: Sun, 22 Oct 2017 08:44:21 +0900 (JST)
Subject: [ruby-changes:48212] sonots:r60327 (trunk): * object.c: Improve documentation of Kernel#Array
sonots 2017-10-22 08:44:15 +0900 (Sun, 22 Oct 2017) New Revision: 60327 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60327 Log: * 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] Modified files: trunk/object.c Index: object.c =================================================================== --- object.c (revision 60326) +++ object.c (revision 60327) @@ -3609,8 +3609,17 @@ rb_Array(VALUE val) https://github.com/ruby/ruby/blob/trunk/object.c#L3609 * 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/