From f51ac9e78014b6be531b4413de79fb041721df11 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 28 Oct 2009 06:51:25 -0700 Subject: Array.wrap(struct) needs to return the wrapped struct --- .../lib/active_support/core_ext/array/wrap.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index 63b6640843..38bb68c1ec 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -1,19 +1,14 @@ 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. - array = Array("foo\nbar") - - if array.size == 1 - def self.wrap(object) + def self.wrap(object) + if object.nil? + [] + # 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 Array(object) end - else - def self.wrap(object) - if object.is_a?(String) - [object] - else - Array(object) - end - end end end -- cgit v1.2.3