rails/rails — pull request #16045 by drueck (2014-07-03 23:02:14+00:00)
Title: Return self from model.readonly!

Currently the result of calling `readonly!` on an ActiveRecord model is always true rather than `self`, so it can't be used for a fluent interface or returned directly. As a result, to create and return a read only instance of a model you would need something like:

```ruby
model = Model.new(attrs)
model.readonly!
model
```

or more concisely, but still a little awkward:

```ruby
Model.new(attrs).tap(&:readonly!)
```

It would be nice to be able to just return the value directly like:

```ruby
Model.new(attrs).readonly!
```

I wasn't sure if it was a conscious decision not to do this, perhaps command query separation? but there is some precedent in methods such as the bang methods on `String` or the semi-analogous `Object#freeze` that each return `self` (if successful).

Thanks for the consideration/feedback!