Saving *args to database

Hi,

I am trying to find a way to save arguments (*args) of a method in
database.
So that when retrieving values from database, coupled with the method
name, I would be able to go:
foo.send(method, *args)

Is it possible to use binary to save this args object?
Would there not be instantiation problems for arguments, so I would not
use the right object type when retrieving their values?

I could not find any similar process on the web. And I am not sure in
which direction to go…

Any thought would be helpful !

Thanks

On 10/4/07, Fred P. [email protected] wrote:

Would there not be instantiation problems for arguments, so I would not
use the right object type when retrieving their values?

I’m not sure exactly what you’re asking. Perhaps you want
serialization of objects in text columns? Look at the docs for
ActiveRecord::Base, or Google “activerecord serialize”

On 4 Oct 2007, at 13:39, Fred P. wrote:

Would there not be instantiation problems for arguments, so I would
not
use the right object type when retrieving their values?

You can use Marshal.dump/Marshal.load to serialize objects.
ActiveRecord also has the serialize method:

class Foo < ActiveRecord::Base
serialize :bar
end

upon saving bar will be serialized using yaml.
Some objects (eg procs) can’t be dumped.

Fred

If we understand you correctly you should serialize args to a database
field and desterilize it when needed.
You could use json format for this serialization/destabilization
purpose.
Anyhow, what ever formats you choose stay a way from binary one.

dima wrote:

If we understand you correctly you should serialize args to a database
field and desterilize it when needed.
You could use json format for this serialization/destabilization
purpose.
Anyhow, what ever formats you choose stay a way from binary one.

Ok I’ll try to use that serialization.

Thanks for your help! This is what I was looking for.

Fred

I all works just fine!

Impressive the way “serialize :args” did all the work for me… whatever
type it is in the array when saving, it will give me the same one back
on deserialization.

Thanks for your great input.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs