Re: [Rails-core] ActiveResource::Base#dup should take standard new/create args

28 views
Skip to first unread message

Duncan Beevers

unread,
Jul 9, 2012, 2:56:13 PM7/9/12
to rubyonra...@googlegroups.com
Sounds nice.

On Mon, Jul 9, 2012 at 12:23 PM, Kurt Werle <ku...@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 rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-co...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.

Nicolas Sanguinetti

unread,
Jul 9, 2012, 3:10:07 PM7/9/12
to rubyonra...@googlegroups.com, rubyonra...@googlegroups.com
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


Steve Klabnik

unread,
Jul 9, 2012, 3:26:18 PM7/9/12
to rubyonra...@googlegroups.com
Not only breaking Ruby semantics, but you can get what you want with this:

some_record.dup.tap do |dup_record|

Francesco Rodriguez

unread,
Jul 9, 2012, 3:22:07 PM7/9/12
to rubyonra...@googlegroups.com

What about initialize_dup?

Nicolás Sanguinetti

unread,
Jul 9, 2012, 5:19:20 PM7/9/12
to rubyonra...@googlegroups.com
On Mon, Jul 9, 2012 at 4:22 PM, Francesco Rodriguez
<lrodrig...@gmail.com> wrote:
> What about initialize_dup?

What about it?

-f

Kurt Werle

unread,
Jul 10, 2012, 11:36:10 AM7/10/12
to rubyonra...@googlegroups.com
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

Nicolás Sanguinetti

unread,
Jul 10, 2012, 11:49:00 AM7/10/12
to rubyonra...@googlegroups.com
On Tue, Jul 10, 2012 at 12:36 PM, Kurt Werle <ku...@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.
Reply all
Reply to author
Forward
0 new messages