Lately I’ve been using a nice alias for writing record attributes in Rails,
 pry(main)> d = Developer.new => #<Developer:0x007ff7130f8ef0  pry(main)> d[:username] = 'isaacemard' => "isaacemard"  pry(main)> d.username => "isaacemard"
That’s all it takes. There’s a getter variant, too:
 pry(main)> d[:username] => "isaacemard"
Here’s how I used it today:
# app/models/developer.rb before_create :generate_slug def generate_slug self[:slug] ||= SecureRandom.hex(5) end
To me this code reads a lot more nicely than
write_attribute(attr_name, value). These aliases have been a part of Rails since at least 2012.
h/t Mike Chau and Chris ErinTweet