aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array
diff options
context:
space:
mode:
authorWill Bryant <will.bryant@gmail.com>2009-02-11 14:49:01 +1300
committerJeremy Kemper <jeremy@bitsweat.net>2009-02-10 18:03:33 -0800
commit1a2a71333f197e98d1cd7fe380d613cbada4446b (patch)
tree7e82866fd3af0945580c0fc0e8bc0e86d2abd91f /activesupport/lib/active_support/core_ext/array
parentff3fb6c5f3b2a0592189545f6f24ef759df6a12e (diff)
downloadrails-1a2a71333f197e98d1cd7fe380d613cbada4446b.tar.gz
rails-1a2a71333f197e98d1cd7fe380d613cbada4446b.tar.bz2
rails-1a2a71333f197e98d1cd7fe380d613cbada4446b.zip
Array#wrap should use #to_ary so association collections and named scopes are not re-wrapped
[#1935 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array')
-rw-r--r--activesupport/lib/active_support/core_ext/array/wrapper.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/wrapper.rb b/activesupport/lib/active_support/core_ext/array/wrapper.rb
index 12fd745b1a..80b8f05531 100644
--- a/activesupport/lib/active_support/core_ext/array/wrapper.rb
+++ b/activesupport/lib/active_support/core_ext/array/wrapper.rb
@@ -2,7 +2,8 @@ module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
module Array #:nodoc:
module Wrapper
- # Wraps the object in an Array unless it's an Array.
+ # Wraps the object in an Array unless it's an Array. Converts the
+ # object to an Array using #to_ary if it implements that.
def wrap(object)
case object
when nil
@@ -10,7 +11,11 @@ module ActiveSupport #:nodoc:
when self
object
else
- [object]
+ if object.respond_to?(:to_ary)
+ object.to_ary
+ else
+ [object]
+ end
end
end
end