File: active_support/core_ext/array/extract_options.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#1
  module: CoreExtensions#2
  module: Array#3
  module: ExtractOptions#4
has properties
method: extract_options! #14

Code

   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