aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array/wrap.rb
blob: 63b6640843cb64c5ef1f92405b5cd5c233d5362c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.
  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
end