Sean O'Halpin
3/12/2008 2:11:00 AM
Hi James!
On Mon, Mar 10, 2008 at 11:08 AM, James Adam <james.adam@gmail.com> wrote:
>
> Are there any cases where you'd want to use "collect", but not ":init => []" ?
:collect works for anything that provides a :<< method, though I've
only tested it with Array, String, StringIO and Set.
But initializing with an Array if you use :collect on its own without
specifying an initial value might be useful (though I'm not keen to
have too much 'magic' in there).
>
> I think it'd also be really interesting to hear if you were using this
> library for anything specific - importing data, for example?
Funny you should mention that :) One use is for validating
quasi-freeform text records of the form:
field1: value
field2: value
field1: value
field2: value
where both field and value have to be validated as well as the whole
record once assembled.
Another is for config files (sometimes yaml just gets too confusing
and you still have to validate anyway).
A colleague at work is using it for a DSL (which is where the Event
example comes from and what prompted me to release it as a gem).
>
> Looks very interesting though!
>
Well, it's been keeping me occupied through the cold winter nights :)
Best regards,
Sean