我想这样做如下: class String
def fancy_thing appendix
# Just a trivial example to ensure self and params work.
# Pretend this is something complex.
self.reverse + appendix
end
end
我有一个作家类: 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:0x21e