From 676b0c87642786080ab9e22fcc86a13d15324d4b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 6 Feb 2009 10:04:43 -0800 Subject: Introduce Array.wrap(foo) to wrap the argument in an array unless it's already an array. Wraps nil as an empty array. Use instead of Array(foo) and foo.to_a since they treat String as Enumerable. --- .../lib/active_support/core_ext/array/wrapper.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/array/wrapper.rb (limited to 'activesupport/lib/active_support/core_ext/array') 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 -- cgit v1.2.3