Skip to content
Browse files

Enhance Symbol#to_proc so it works with list objects, such as multi-d…

…imensional arrays. Closes #5295 [nov@yo.rim.or.jp]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4455 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2bbcff8 commit ae0e1a0682c853d0cdc969a82cd23455b4d2ca3e @technoweenie technoweenie committed Jun 17, 2006
View
5 activesupport/CHANGELOG
@@ -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
View
2 activesupport/lib/active_support/core_ext/symbol.rb
@@ -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
View
2 activesupport/test/core_ext/symbol_test.rb
@@ -4,5 +4,7 @@
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

0 comments on commit ae0e1a0

Please sign in to comment.
Something went wrong with that request. Please try again.