On 09/03/2013 12:04 PM, Charles Hixson wrote:
> On 09/03/2013 11:34 AM, Hans Mackowiak wrote:
>> if you want it for storing or transporting data, use different stuff
>> like JSON or Marshal
>>
> Marshall is plausible, but "Programming Ruby" warns that the format is 
> subject to change when the compiler changes.  JSON said that Array 
> didn't have a defined to string method.  (I forget whether it was 
> "to_s" or not.)  I found this a bit odd as my first tests had worked 
> correctly.  So I'm a bit leery of it.
>
> And in answer to the other question, above, it isn't going to be a 
> fixed structure, so no regex could match it.  I suppose I could pull 
> off the start, and recurse whenever I encountered an internal list, 
> but I'd really rather use an off the shelf solution, if possible. YAML 
> would work, but I'd really prefer something a LOT less verbose.
>
> One possibility that occurred to me was to just take the string and 
> modify it into a fake JSON data string, then compose it into a hash 
> with a JSON tag...but if I really trusted JSON to work, the only thing 
> that would gain me would be a bit of compactness. (Highly desirable, 
> but not if I don't trust the underlying method.  And I'm really 
> bothered by the claim that a to string method didn't exist for 
> Array.)  Or perhaps I could modify it into a YAML string, and use YAML 
> to decode it.
>
> So there are ways forwards.  But I've been using eval, and it would be 
> nice if the replacement weren't that much more work.
>
I just tried JSON again, and this time it worked.  Perhaps it just 
couldn't deal with a class instance being present in an internal Array, 
though it handled it fine when it was on the outer level. JSON is 
clearly much more compact than YAML.  It only added around 4 characters 
over a straight string representation.  So perhaps I just need to avoid 
classes that use themselves to serialize and deserialize themselves, and 
stick to the basic list representation.

-- 
Charles Hixson