Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7217

Show
Ignore:
Timestamp:
07/24/07 14:17:09 (1 year ago)
Author:
david
Message:

Added Array#extract_options! to encapsulate the pattern of getting an options hash out of a variable number of parameters (closes #8759) [norbert]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r7195 r7217  
    11*SVN* 
     2 
     3* Added Array#extract_options! to encapsulate the pattern of getting an options hash out of a variable number of parameters #8759 [norbert]. 
    24 
    35* Let alias_attribute work with attributes with initial capital letters (legacy columns etc).  Closes #8596 [mpalmer] 
  • trunk/activesupport/lib/active_support/core_ext/array.rb

    r4387 r7217  
    11require File.dirname(__FILE__) + '/array/conversions' 
    22require File.dirname(__FILE__) + '/array/grouping' 
     3require File.dirname(__FILE__) + '/array/extract_options' 
    34 
    45class Array #:nodoc: 
    56  include ActiveSupport::CoreExtensions::Array::Conversions 
    67  include ActiveSupport::CoreExtensions::Array::Grouping 
     8  include ActiveSupport::CoreExtensions::Array::ExtractOptions 
    79end 
  • trunk/activesupport/test/core_ext/array_ext_test.rb

    r7074 r7217  
    192192  end 
    193193end 
     194 
     195class ArrayExtractOptionsTests < Test::Unit::TestCase 
     196  def test_extract_options 
     197    assert_equal({}, [].extract_options!) 
     198    assert_equal({}, [1].extract_options!) 
     199    assert_equal({:a=>:b}, [{:a=>:b}].extract_options!) 
     200    assert_equal({:a=>:b}, [1, {:a=>:b}].extract_options!) 
     201  end 
     202end