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] <javascript:>> 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] <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.
