什么是“更好”的是 Ruby
class BaseClass
def items
@items ||= get_items
end
def get_items
raise NotImplementedError
end
end
class ClildClass < BaseClass
def get_items
# ... fetching items...
end
end
或者干脆
class BaseClass
def items
@items ||= get_items
end
end
class ClildClass < BaseClass
def get_items
# ... fetching items...
end
end
?