Sha256: 23de43f68b4304f660709461e5de8fc0691ef528f54ac21aa671a23896f96a81

Contents?: true

Size: 795 Bytes

Versions: 229

Compression:

Stored size: 795 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

229 entries across 220 versions & 23 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/core_ext/array/extract_options.rb
activesupport-4.2.11.3 lib/active_support/core_ext/array/extract_options.rb
activesupport-4.2.11.2 lib/active_support/core_ext/array/extract_options.rb
sigterm_extensions-0.0.4 lib/sigterm_extensions/core_ext/array/extract_options.rb
opal-activesupport-0.3.3 opal/active_support/core_ext/array/extract_options.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/array/extract_options.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/array/extract_options.rb
opal-activesupport-0.3.2 opal/active_support/core_ext/array/extract_options.rb
activesupport-5.1.7 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.1.7.rc1 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.1.6.2 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.0.7.2 lib/active_support/core_ext/array/extract_options.rb
activesupport-4.2.11.1 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.1.6.1 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.0.7.1 lib/active_support/core_ext/array/extract_options.rb
activesupport-4.2.11 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.1.6 lib/active_support/core_ext/array/extract_options.rb
activesupport-5.0.7 lib/active_support/core_ext/array/extract_options.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/core_ext/array/extract_options.rb
activesupport-5.1.5 lib/active_support/core_ext/array/extract_options.rb