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

Changeset 4455

Show
Ignore:
Timestamp:
06/17/06 03:01:57 (2 years ago)
Author:
rick
Message:

Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp]

Files:

Legend:

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

    r4453 r4455  
    11*SVN* 
     2 
     3* Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp].  Example: 
     4 
     5    {1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last) 
     6    #=> ["one", "two", "three"] 
    27 
    38* Added Hash.create_from_xml(string) which will create a hash from a XML string and even typecast if possible [DHH]. Example: 
  • trunk/activesupport/lib/active_support/core_ext/symbol.rb

    r4139 r4455  
    88  #   people.select(&:manager?).collect(&:salary) 
    99  def to_proc 
    10     Proc.new { |obj, *args| obj.send(self, *args) } 
     10    Proc.new { |*args| args.shift.__send__(self, *args) } 
    1111  end 
    1212end 
  • trunk/activesupport/test/core_ext/symbol_test.rb

    r4158 r4455  
    55  def test_to_proc 
    66    assert_equal %w(one two three), [:one, :two, :three].map(&:to_s) 
     7    assert_equal(%w(one two three), 
     8      {1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last)) 
    79  end 
    810end