Kurt Werle
2012-Jul-09 17:23 UTC
ActiveResource::Base#dup should take standard new/create args
dup takes no args create and new both take the same args, and create can take a block It seems to me it would be more consistent (and convenient) if I could do some_record.dup(attributes_i_want_to_change) do |dup_record| dup_record.attribute = some_value self.relationship.dup(reverse_relationship: dup_record) end I''d be happy to throw some code & tests at this (seems like it''d be a trivial change) if it seems like the right thing to do. Thanks, Kurt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/YUQy_CN1B3UJ. 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.
Duncan Beevers
2012-Jul-09 18:56 UTC
Re: ActiveResource::Base#dup should take standard new/create args
Sounds nice. On Mon, Jul 9, 2012 at 12:23 PM, Kurt Werle <kurt@circlew.org> wrote:> dup takes no args > create and new both take the same args, and create can take a block > > It seems to me it would be more consistent (and convenient) if I could do > > some_record.dup(attributes_i_want_to_change) do |dup_record| > dup_record.attribute = some_value > self.relationship.dup(reverse_relationship: dup_record) > end > > I''d be happy to throw some code & tests at this (seems like it''d be a > trivial change) if it seems like the right thing to do. > > Thanks, > Kurt > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/YUQy_CN1B3UJ. > 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.-- 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.
Nicolas Sanguinetti
2012-Jul-09 19:10 UTC
Re: ActiveResource::Base#dup should take standard new/create args
dup doesn''t take arguments because in ruby dup doesn''t take arguments. It wouldn''t make sense to break the semantics of ruby just for this, IMO. Cheers, -foca On 09/07/2012, at 14:23, Kurt Werle <kurt@circlew.org> wrote:> dup takes no args > create and new both take the same args, and create can take a block > > It seems to me it would be more consistent (and convenient) if I could do > > some_record.dup(attributes_i_want_to_change) do |dup_record| > dup_record.attribute = some_value > self.relationship.dup(reverse_relationship: dup_record) > end > > I''d be happy to throw some code & tests at this (seems like it''d be a trivial change) if it seems like the right thing to do. > > Thanks, > Kurt > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/YUQy_CN1B3UJ. > 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.-- 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.
Francesco Rodriguez
2012-Jul-09 19:22 UTC
Re: ActiveResource::Base#dup should take standard new/create args
What about initialize_dup? El jul 9, 2012 2:11 p.m., "Nicolas Sanguinetti" <godfoca@gmail.com> escribió:> dup doesn''t take arguments because in ruby dup doesn''t take arguments. It > wouldn''t make sense to break the semantics of ruby just for this, IMO. > > Cheers, > -foca > > > > On 09/07/2012, at 14:23, Kurt Werle <kurt@circlew.org> wrote: > > dup takes no args > create and new both take the same args, and create can take a block > > It seems to me it would be more consistent (and convenient) if I could do > > some_record.dup(attributes_i_want_to_change) do |dup_record| > dup_record.attribute = some_value > self.relationship.dup(reverse_relationship: dup_record) > end > > I''d be happy to throw some code & tests at this (seems like it''d be a > trivial change) if it seems like the right thing to do. > > Thanks, > Kurt > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/YUQy_CN1B3UJ. > 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. > > -- > 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. >-- 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.
Steve Klabnik
2012-Jul-09 19:26 UTC
Re: ActiveResource::Base#dup should take standard new/create args
Not only breaking Ruby semantics, but you can get what you want with this: some_record.dup.tap do |dup_record| dup_record.attribute = some_value self.relationship.dup(reverse_relationship: dup_record) end -- 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.
Nicolás Sanguinetti
2012-Jul-09 21:19 UTC
Re: ActiveResource::Base#dup should take standard new/create args
On Mon, Jul 9, 2012 at 4:22 PM, Francesco Rodriguez <lrodriguezsanc@gmail.com> wrote:> What about initialize_dup?What about it? -f> > El jul 9, 2012 2:11 p.m., "Nicolas Sanguinetti" <godfoca@gmail.com> > escribió: > >> dup doesn''t take arguments because in ruby dup doesn''t take arguments. It >> wouldn''t make sense to break the semantics of ruby just for this, IMO. >> >> Cheers, >> -foca >> >> >> >> On 09/07/2012, at 14:23, Kurt Werle <kurt@circlew.org> wrote: >> >> dup takes no args >> create and new both take the same args, and create can take a block >> >> It seems to me it would be more consistent (and convenient) if I could do >> >> some_record.dup(attributes_i_want_to_change) do |dup_record| >> dup_record.attribute = some_value >> self.relationship.dup(reverse_relationship: dup_record) >> end >> >> I''d be happy to throw some code & tests at this (seems like it''d be a >> trivial change) if it seems like the right thing to do. >> >> Thanks, >> Kurt >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-core/-/YUQy_CN1B3UJ. >> 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. >> >> -- >> 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. > > -- > 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.-- 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.
Kurt Werle
2012-Jul-10 15:36 UTC
Re: ActiveResource::Base#dup should take standard new/create args
On Monday, July 9, 2012 12:10:07 PM UTC-7, Nicolás Sanguinetti wrote:> > dup doesn''t take arguments because in ruby dup doesn''t take arguments. It > wouldn''t make sense to break the semantics of ruby just for this, IMO. >I had not considered that. On the other hand: * it''s not like dup calls super (which seems wrong to me, now that I think about it) * dup with no args would continue to behave exactly the same as it does, now Kurt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/xB0hhO8wXqwJ. 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.
Nicolás Sanguinetti
2012-Jul-10 15:49 UTC
Re: ActiveResource::Base#dup should take standard new/create args
On Tue, Jul 10, 2012 at 12:36 PM, Kurt Werle <kurt@circlew.org> wrote:> On Monday, July 9, 2012 12:10:07 PM UTC-7, Nicolás Sanguinetti wrote: >> >> dup doesn''t take arguments because in ruby dup doesn''t take arguments. It >> wouldn''t make sense to break the semantics of ruby just for this, IMO. > > > I had not considered that. On the other hand: > * it''s not like dup calls super (which seems wrong to me, now that I think > about it)Well, the thing is, you are not supposed to redefine #dup, the same way you''re not supposed to redefine Class#new and instead use Object#initialize. With #dup, however, you''re supposed to implement #initialize_copy, that takes the object you want to make a shallow copy of. Cheers, -foca> * dup with no args would continue to behave exactly the same as it does, now > > Kurt > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/xB0hhO8wXqwJ. > > 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.-- 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.