我有一个作家类: 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
在Grails应用程序中,我正在寻找一些方法将数据从控制器操作传递到操作后运行的过滤器。我喜欢思考的东西: class MyController {
def myAction = {
render(view:"myView", model:[key: "value"])
passData {
// Do some processing here
假设我希望某个字符串的实例与其他“正常”实例的行为不同,例如取消“upcase”方法的效果。我做到以下几点: class String
def foo
def self.upcase
self
end
self
end
end
这似乎很好地工作,而我需要的方式: puts "bar".upcase #=> "BAR"
puts