This is all that's needed in 1.8.7+

This commit is contained in:
Yehuda Katz
2009-10-28 01:43:33 -07:00
parent c5e73b8976
commit a0fc92f455

View File

@@ -1,17 +1,18 @@
class Array
# Wraps the object in an Array unless it's an Array. Converts the
# object to an Array using #to_ary if it implements that.
def self.wrap(object)
case object
when nil
[]
when self
object
else
if object.respond_to?(:to_ary)
object.to_ary
else
array = Array("foo\nbar")
if array.size == 1
def self.wrap(object)
Array(object)
end
else
def self.wrap(object)
if object.is_a?(String)
[object]
else
Array(object)
end
end
end