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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/4/07, Fred Penz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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''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" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4 Oct 2007, at 13:39, Fred Penz wrote:> > 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? >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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On Oct 4, 2:49 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10/4/07, Fred Penz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > 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''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"--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---