著者クラスがあります:
class Author < ActiveRecord::Base
def to_s
name
end
end
定義to_s
することで私はできますがputs Author.first
、できませんputs Author.first.rjust(10)
:
NoMethodError: undefined method `rjust' for #<Author:0x21eb5d4>
to_s
このような場合、Rubyが文字列メソッドの前に自動的に試行したほうがよいのではないでしょうか。この動作を取得する方法はありますか?