aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array/wrap.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/wrap.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/array/wrap.rb14
1 files changed, 5 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb
index 9d45c2739b..38bb68c1ec 100644
--- a/activesupport/lib/active_support/core_ext/array/wrap.rb
+++ b/activesupport/lib/active_support/core_ext/array/wrap.rb
@@ -2,17 +2,13 @@ class 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 self.wrap(object)
- case object
- when nil
+ if object.nil?
[]
- when self
- object
+ # to_a doesn't work correctly with Array() but to_ary always does
+ elsif object.respond_to?(:to_a) && !object.respond_to?(:to_ary)
+ [object]
else
- if object.respond_to?(:to_ary)
- object.to_ary
- else
- [object]
- end
+ Array(object)
end
end
end