Sha256: dcda0b240a9573100ad54b8c69d2338770439ddd6290ce393dfce33262ee5c54

Contents?: true

Size: 801 Bytes

Versions: 371

Compression:

Stored size: 801 Bytes

Contents

class Hash
  # By default, only instances of Hash itself are extractable.
  # Subclasses of Hash may implement this method and return
  # true to declare themselves as extractable. If a Hash
  # is extractable, Array#extract_options! pops it from
  # the Array when it is the last element of the Array.
  def extractable_options?
    instance_of?(Hash)
  end
end

class Array
  # Extracts options from a set of arguments. Removes and returns the last
  # element in the array if it's a hash, otherwise returns a blank hash.
  #
  #   def options(*args)
  #     args.extract_options!
  #   end
  #
  #   options(1, 2)           # => {}
  #   options(1, 2, :a => :b) # => {:a=>:b}
  def extract_options!
    if last.is_a?(Hash) && last.extractable_options?
      pop
    else
      {}
    end
  end
end

Version data entries

371 entries across 327 versions & 32 rubygems

Version Path
challah-rolls-0.2.0 vendor/bundle/gems/activesupport-3.2.7/lib/active_support/core_ext/array/extract_options.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/extract_options.rb
challah-0.8.3 vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/extract_options.rb
challah-0.8.3 vendor/bundle/gems/activesupport-3.2.8/lib/active_support/core_ext/array/extract_options.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.8 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb
activesupport-3.2.9 lib/active_support/core_ext/array/extract_options.rb
activesupport-3.2.9.rc3 lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.7 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb
activesupport-3.2.9.rc2 lib/active_support/core_ext/array/extract_options.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/core_ext/array/extract_options.rb
activesupport-3.2.9.rc1 lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.6 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.5 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.4 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/extract_options.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/extract_options.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.3 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb
classiccms-0.6.2 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/extract_options.rb