documentcloud/underscore — Issue #367: toArray should convert a single element into an array
Author: sreeix
Created: 2011-11-10 21:45:30+00:00
State: open

One of the patterns i use in Ruby is

def foo (category)
Array(category).each{|item| puts item}
end

It would be nice to have something like this with toArray as well. Instead of (in coffeescript)

keywords = if _.isArray(doc.keywords) then doc.keywords else [doc.keywords]

Is there a better way of doing this?

If you think it is useful, i can provide a patch for it.