On 04.12.2006 13:06, Peter Szinek wrote:
>> Where do you need that for?
> 
> I am setting up a complicated object (similar to a tree) with this code:
> 
> crap = define_my_object do
>          foo do
>            bar
>            baz do
>              fluff :something => :hairy
>              ork :something => :other
>            end
>          end
>        end
> 
> now, I would like to call a few methods on 'crap' which will alter the 
> state of the object and eventually call a function which spits out crap as:
> 
> crap = define_my_object do
>          foo do
>            bar :some => :new_param_here
>            baz do
>              fluff :now => :here, :are => :some, :other => things
>              ork :and => :even, :more => nil
>            end
>          end
>        end

So you are modifying the state of an object and want to emit code that 
will recreate this state?

> I have been thinking about some kind of serialization which would be 
> certainly possible just by knowing crap - but since everything remains 
> the same except a few parameters, it seemed easier to me to
> sub! (':something => :hairy') {':now => :here, :are => :some, :other => 
> things'} etc. - but for this I need the string of the original block of 
> course.

I would rather go serialization - if you use YAML the serialized state 
is actually human readable (sort of).  Marshal is binary but also faster 
IIRC.  I would *definitively* go serialization if you want to store 
configuration state between script executions.

Kind regards

	robert