I've been using Array(obj) to ensure the obj is an Array. With 1.8.8
this now warns if the argument is a String:
$ ruby18 -ve 'p Array(5)'
ruby 1.8.8dev (2009-04-06 revision 23143) [i386-darwin9.6.0]
[5]
$ ruby18 -ve 'p Array("string")'
ruby 1.8.8dev (2009-04-06 revision 23143) [i386-darwin9.6.0]
-e:1: warning: treating String as Enumerable object is deprecated; use
String#each_line/lines
["string"]
I believe the warning is due to this behavior:
$ ruby18 -ve 'p Array("multi-line\nstring")'
ruby 1.8.8dev (2009-04-06 revision 23143) [i386-darwin9.6.0]
-e:1: warning: treating String as Enumerable object is deprecated; use
String#each_line/lines
["multi-line\n", "string"]
I find it strange that Array would warn in this instance, I thought
Kernel#Array as supposed to be used as a cast. Having a warning makes
it less useful and makes it cumbersome to ensure an argument is an
Array.
PS: I really wouldn't mind if this last instance returned ["multi-line
\nstring"]