Created
March 24, 2014 15:47
-
-
Save aratak/9742918 to your computer and use it in GitHub Desktop.
Array wrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/array_wrap.rb | |
class Array | |
def self.wrap(object) | |
if object.nil? | |
[] | |
elsif object.respond_to?(:to_ary) | |
object.to_ary || [object] | |
else | |
[object] | |
end | |
end | |
end unless Array.respond_to? :wrap | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment