~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/array/extract_options.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 ExtractOptions
5
 
        # Extracts options from a set of arguments. Removes and returns the last
6
 
        # element in the array if it's a hash, otherwise returns a blank hash.
7
 
        #
8
 
        #   def options(*args)
9
 
        #     args.extract_options!
10
 
        #   end
11
 
        #
12
 
        #   options(1, 2)           # => {}
13
 
        #   options(1, 2, :a => :b) # => {:a=>:b}
14
 
        def extract_options!
15
 
          last.is_a?(::Hash) ? pop : {}
16
 
        end
17
 
      end
18
 
    end
19
 
  end
20
 
end