~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: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

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