鉴于我有一个继承自的类Draper::Decorator,如下所示:
class PageDecorator < Draper::Decorator
delegate_all
delegate :title, :name, :region, :keys,
to: :glass_decorator,
prefix: :glass
def full_title
full_title = []
full_title << glass_title if glass_title
full_title.join(" ")
end
GlassDecorator在同一目录中的另一个文件中调用了一个装饰器。
这条
delegate线实际上是什么意思?这是否意味着当我尝试访问title、name、region、keys属性/方法时,它们将被委托给GlassDecorator? 部分是什么prefix:意思?对于
full_title方法,glass_title部件是否尝试title在 ? 中查找属性/方法GlassDecorator?如果是这样的话,难道仅仅是因为这delegate条线才成为可能吗?如果是这样,它是:prefix使它成为可能的部分吗?
谢谢你。