aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/array.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/wrapper.rb19
2 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb
index cc0a1ebc12..82c6b1243a 100644
--- a/activesupport/lib/active_support/core_ext/array.rb
+++ b/activesupport/lib/active_support/core_ext/array.rb
@@ -3,6 +3,7 @@ require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/grouping'
require 'active_support/core_ext/array/random_access'
+require 'active_support/core_ext/array/wrapper'
class Array #:nodoc:
include ActiveSupport::CoreExtensions::Array::Access
@@ -10,4 +11,5 @@ class Array #:nodoc:
include ActiveSupport::CoreExtensions::Array::ExtractOptions
include ActiveSupport::CoreExtensions::Array::Grouping
include ActiveSupport::CoreExtensions::Array::RandomAccess
+ extend ActiveSupport::CoreExtensions::Array::Wrapper
end
diff --git a/activesupport/lib/active_support/core_ext/array/wrapper.rb b/activesupport/lib/active_support/core_ext/array/wrapper.rb
new file mode 100644
index 0000000000..12fd745b1a
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/array/wrapper.rb
@@ -0,0 +1,19 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Array #:nodoc:
+ module Wrapper
+ # Wraps the object in an Array unless it's an Array.
+ def wrap(object)
+ case object
+ when nil
+ []
+ when self
+ object
+ else
+ [object]
+ end
+ end
+ end
+ end
+ end
+end