I'm parsing JSON from an API. I have a foo element that's a hash sometimes, and an array of hashes, other times.
foo: { ... }
foo: [
{ ... },
{ ... }
]
I'd like to just use Array(foo) to always get the an array with at least the one element, but it converts the hash to [[..., ...], [..., ...]]. Is there an elegant way to handle this, besides using foo.is_a?(Hash/Array)?
ActiveSupportto perform a simple calculation? There's nothing simpler than the way @Veet does it. Even if the lack of a Rails tag was an oversight, you cannot very well add it now.