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

Changeset 7172

Show
Ignore:
Timestamp:
07/09/07 21:49:37 (2 years ago)
Author:
david
Message:

Added Hash#except which is the inverse of Hash#slice -- return the hash except the keys that are specified [DHH]

Files:

Legend:

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

    r7092 r7172  
    11*SVN* 
     2 
     3* Added Hash#except which is the inverse of Hash#slice -- return the hash except the keys that are specified [DHH] 
    24 
    35* Added support for pluralization with a different starting letter than the singular version (cow/kine) #4929 [norri_b/hasmanyjosh] 
  • trunk/activesupport/lib/active_support/core_ext/hash.rb

    r5726 r7172  
    1 %w(keys indifferent_access reverse_merge conversions diff slice).each do |ext| 
     1%w(keys indifferent_access reverse_merge conversions diff slice except).each do |ext| 
    22  require "#{File.dirname(__FILE__)}/hash/#{ext}" 
    33end 
     
    1010  include ActiveSupport::CoreExtensions::Hash::Diff 
    1111  include ActiveSupport::CoreExtensions::Hash::Slice 
     12  include ActiveSupport::CoreExtensions::Hash::Except 
    1213end 
  • trunk/activesupport/test/core_ext/hash_ext_test.rb

    r7074 r7172  
    277277      assert_equal expected, copy 
    278278    end 
     279  end 
     280 
     281  def test_except 
     282    original = { :a => 'x', :b => 'y', :c => 10 } 
     283    expected = { :a => 'x', :b => 'y' } 
     284 
     285    # Should return a new hash with only the given keys. 
     286    assert_equal expected, original.except(:c) 
     287    assert_not_equal expected, original 
     288 
     289    # Should replace the hash with only the given keys. 
     290    assert_equal expected, original.except!(:c) 
     291    assert_equal expected, original 
    279292  end 
    280293end