Thanks for chiming in, John. Do you think it's worth submitting my small PR 
at this point, or would it be better to try to get more input here first?

-David

On Thursday, July 3, 2014 2:57:39 PM UTC-7, John Mileham wrote:
>
> Agreed it's a super minor issue, but I personally like David's proposal. 
> It seems like ruby's Object#freeze is a strong analog and precedent for 
> returning the mutated object and enabling a fluent interface.  It doesn't 
> look like there was an explicit decision behind the current behavior, it's 
> just the natural result of the current one-line implementation 
> <https://github.com/rails/rails/blob/f625b6879df4d8710c0226007dc0929ed98355d2/activerecord/lib/active_record/core.rb#L408>
> .
>
> -john
>
>
> On Thu, Jul 3, 2014 at 5:06 PM, David Rueck <[email protected] 
> <javascript:>> wrote:
>
>> Ah, thanks for the reminder about using tap!
>>
>> I'm still curious, though, if it would be a better API to return self or 
>> if there is a reason/precedent not to. I thought maybe command query 
>> separation was the reason, but it seems like enabling a fluent syntax by 
>> returning self is a good exception to that principle. For example, the bang 
>> methods on String return the string if successful, which is very convenient.
>>
>> It's not a big deal, obviously, as tap works fine, but I'm just curious. 
>> Thanks so much for taking the time to respond!
>>
>> -David
>>
>>
>> On Wednesday, July 2, 2014 10:49:29 PM UTC-7, Geoffrey Roguelon wrote:
>>
>>> Hi,
>>>
>>> Maybe, can you use the method #tap?
>>>
>>> model = Model.new(attrs).tap(&:readonly!)
>>>
>>> Best regards.
>>>
>>> -----
>>> Geoffrey Roguelon
>>>
>>> Le 3 juil. 2014 à 02:10, David Rueck <[email protected]> a écrit :
>>>
>>> I was wondering if it would make sense to return self from the readonly! 
>>> method of an ActiveRecord model? I found myself wanting to create a list of 
>>> read only instances and it seemed unnecessarily verbose to do
>>>
>>> model = Model.new(attrs)
>>> model.readonly!
>>> model
>>>
>>> for each of them instead of just
>>>
>>> Model.new(attrs).readonly!
>>>
>>> I've got the super small patch prepared, but I wanted to run it by some 
>>> folks before adding it to the rather large list of pull requests!
>>>
>>> Thanks,
>>>
>>> -David
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Ruby on Rails: Core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>>
>>> Visit this group at http://groups.google.com/group/rubyonrails-core.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/rubyonrails-core.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to