Hi, One of the fundamental methods share by both ActiveSupport and Facets is Hash#slice!. A few days ago, someone pointed out to me that the two libs in this case are not quite the same. Quote, "I got hosed by a lovely bug stemming from facets'' and rails'' slice! returning opposite things... facets returns the key,value pairs not matched by the keys passed, great because it gives you two things back at once, though slice and slice! return different things. rails returns the key,value pairs matched, that is, slice and slice! have the same return" Generally I let Facets defer to the behavior of ActiveSupport when there is a conflict, but in this case the Facets implementation seems more useful and is also more in line to similar methods in core Ruby, ie. Array#slice!, which also returns the deleted items. So I was hoping that Rails could be modified to support this alternate implementation of Hash#slice!. Thanks, T. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, Sep 1, 2008 at 2:14 PM, 7rans <transfire@gmail.com> wrote:> > Hi, > > One of the fundamental methods share by both ActiveSupport and Facets > is > Hash#slice!. A few days ago, someone pointed out to me that the two > libs > in this case are not quite the same. Quote, "I got hosed by a lovely > bug > stemming from facets'' and rails'' slice! returning opposite things... > facets returns the key,value pairs not matched by the keys passed, > great > because it gives you two things back at once, though slice and slice! > return different things. rails returns the key,value pairs matched, > that is, slice and slice! have the same return" > > Generally I let Facets defer to the behavior of ActiveSupport when > there > is a conflict, but in this case the Facets implementation seems more > useful and is also more in line to similar methods in core Ruby, ie. > Array#slice!, which also returns the deleted items. > > So I was hoping that Rails could be modified to support this alternate > implementation of Hash#slice!.We do have tests which assert that that''s the result returned, but they''ve been there from the beginning: http://github.com/rails/rails/tree/86deb270953f9c5b62813d3e1938f33cc807bd7f If you want to take a look at making that change, we can have a look to see if it breaks anything else. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 2, 11:48 am, "Michael Koziarski" <mich...@koziarski.com> wrote:> > We do have tests which assert that that''s the result returned, but > they''ve been there from the beginning: > > http://github.com/rails/rails/tree/86deb270953f9c5b62813d3e1938f33cc8... > > If you want to take a look at making that change, we can have a look > to see if it breaks anything else.Ok. I''ve done it. # Replaces the hash with only the given keys. def slice!(*keys) keys = keys.map! { |key| convert_key(key) } if respond_to? (:convert_key) omit = slice(*self.keys - keys) hash = slice(*keys) replace(hash) omit end I also updated the tests. Should I submit a patch? How do I proceed? Thanks, T. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> I also updated the tests. Should I submit a patch? How do I proceed?You should create a patch following the guidelines we have on lighthouse: http://rails.lighthouseapp.com/projects/8994/sending-patches Once that''s done you can attach it to a new ticket and ask people for feedback on it. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 4, 4:13 am, "Michael Koziarski" <mich...@koziarski.com> wrote:> > I also updated the tests. Should I submit a patch? How do I proceed? > > You should create a patch following the guidelines we have on lighthouse: > > http://rails.lighthouseapp.com/projects/8994/sending-patches > > Once that''s done you can attach it to a new ticket and ask people for > feedback on it.Done. Ticket #971. Thanks for the help. T. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---