create table books (
id integer primary key auto_increment,
title varchar(256) not null,
price integer
);
というテーブルがあったとき、Book#price は nil を返す可能性があります。
そこで
class Book < ActiveRecord::Base
alias _price price
def price
_price || 0
end
end
みたいなかっこわるいことしてるんですけど、もっといい方法があれば教えてください。