lastobelus
2007-Nov-15 12:16 UTC
(1.6) Hash does not survive Object.clone and subsequent $H()
Instead, _object becomes deeper nested:>>> h=$H({ action: ''ship'', order_id: 123, fees: [''fee1'', ''fee2''] })Object _object=Object>>> hc=Object.clone(h);Object _object=Object>>> h2=$H(hc);Object _object=Object>>> h2._object._objectObject action=ship order_id=123 fees=[2]>>> h2._objectObject _object In particular, this breaks passing a hash as parameters option to Ajax.update. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
lastobelus
2007-Nov-15 12:31 UTC
Re: (1.6) Hash does not survive Object.clone and subsequent $H()
type is not preserved in general:>>> a = new Array[]>>> b=Object.clone(a)Object>>> b instanceof Arrayfalse>>> a instanceof Arraytrue --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tobie Langel
2007-Nov-15 13:24 UTC
Re: (1.6) Hash does not survive Object.clone and subsequent $H()
Hi, If you want to clone a Hash or an Array, you should be using their own instance methods Array#clone and Hash#clone. The fact that you can''t pass a hash to new Ajax.(Request|Update) is a bug and will be corrected in an upcoming 1.6.0.1 version. Regards, Tobie On Nov 15, 1:31 pm, lastobelus <lastobe...-ee4meeAH724@public.gmane.org> wrote:> type is not preserved in general: > > >>> a = new Array > [] > >>> b=Object.clone(a) > Object > >>> b instanceof Array > false > >>> a instanceof Array > > true--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Nicolás Sanguinetti
2007-Nov-15 14:34 UTC
Re: (1.6) Hash does not survive Object.clone and subsequent $H()
On Nov 15, 2007 11:24 AM, Tobie Langel <tobie.langel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > If you want to clone a Hash or an Array, you should be using their own > instance methods Array#clone and Hash#clone.Why not have Object.clone attempt to call clone on the passed object before? It seems to me the most POLSy thing to do. http://dev.rubyonrails.org/ticket/10175 -Nicolas> > > The fact that you can''t pass a hash to new Ajax.(Request|Update) is a > bug and will be corrected in an upcoming 1.6.0.1 version. > > Regards, > > Tobie > > > > > > > On Nov 15, 1:31 pm, lastobelus <lastobe...-ee4meeAH724@public.gmane.org> wrote: > > type is not preserved in general: > > > > >>> a = new Array > > [] > > >>> b=Object.clone(a) > > Object > > >>> b instanceof Array > > false > > >>> a instanceof Array > > > > true > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tobie Langel
2007-Nov-15 14:50 UTC
Re: (1.6) Hash does not survive Object.clone and subsequent $H()
> Why not have Object.clone attempt to call clone on the passed object before? > It seems to me the most POLSy thing to do.That implies adding clone methods all over the place. Currently, in firebug:>>> Object.clone(''foo'');Object 0=f 1=o 2=o>>> typeof Object.clone(''foo'');"object">>> Object.clone(123)Object>>> typeof Object.clone(123)"object" etc. Not really sure if we want to go down that road. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---