~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/array/wrapper.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
module ActiveSupport #:nodoc:
2
 
  module CoreExtensions #:nodoc:
3
 
    module Array #:nodoc:
4
 
      module Wrapper
5
 
        # Wraps the object in an Array unless it's an Array.  Converts the
6
 
        # object to an Array using #to_ary if it implements that.
7
 
        def wrap(object)
8
 
          case object
9
 
          when nil
10
 
            []
11
 
          when self
12
 
            object
13
 
          else
14
 
            if object.respond_to?(:to_ary)
15
 
              object.to_ary
16
 
            else
17
 
              [object]
18
 
            end
19
 
          end
20
 
        end
21
 
      end
22
 
    end
23
 
  end
24
 
end