当需要的节点是属性或方法时,很容易调用extends。
但是当它不是一个属性时呢?它可以是实例变量或 attr 访问器。
下面的例子:
// dispatches is an attribute of the class
child :dispatches => :dispatches do
extends "/dispatches/_base"
end
# completed post is not an attribute of the class
if @completed_post
node(:post) do |post|
{
id: @completed_post.id.to_s,
_id: @completed_post.id.to_s,
display_text: @completed_post.display_text,
# and many others
}
end
这需要的附加节点可以是@instance 或@object[:some_attribute]