mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4455 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
*SVN*
|
||||
|
||||
* Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp]. Example:
|
||||
|
||||
{1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last)
|
||||
#=> ["one", "two", "three"]
|
||||
|
||||
* Added Hash.create_from_xml(string) which will create a hash from a XML string and even typecast if possible [DHH]. Example:
|
||||
|
||||
Hash.create_from_xml <<-EOT
|
||||
|
||||
@@ -7,6 +7,6 @@ class Symbol
|
||||
# # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
|
||||
# people.select(&:manager?).collect(&:salary)
|
||||
def to_proc
|
||||
Proc.new { |obj, *args| obj.send(self, *args) }
|
||||
Proc.new { |*args| args.shift.__send__(self, *args) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,5 +4,7 @@ require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol'
|
||||
class SymbolTests < Test::Unit::TestCase
|
||||
def test_to_proc
|
||||
assert_equal %w(one two three), [:one, :two, :three].map(&:to_s)
|
||||
assert_equal(%w(one two three),
|
||||
{1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user