solnic/virtus — Issue #63: Force to array coercion
Author: v0n
Created: 2012-02-09 20:12:40+00:00
State: open

It'd be great if an attribute of type Array could be automatically converted to an array.

Example use case:
In a Sinatra app, an URL formatted like `?key=value` results in `params['key'] = 'value'`, while `?key[]=value1&key[]=value2` results in `params['key'] = ['value1', 'value2']`.
I'd like to deal with an array all the time. i.e. `VirtusObject.new(:key => 1).key # => [1]`.

On #datamapper, Solnic suggested something like:

class Virtus::Coercion::Object; def self.to_array(value); Array(value); end; end

Best,
Vivien.