我想find_items在子类中覆盖 Item 的方法UserItem。我应该将该方法添加为protectedorprivate吗?
我现在可以在子类中使用受保护的方法,并且只能在它们所属的类中使用私有方法。
class Item
  def item_ids
    @ids ||= REDIS.zrevrange(key, 0, 100).map(&:to_i)
  end
  def items
    find_items
    item_ids.collect {|id| records.detect {|x| x.id == id}}.compact.map(&:content)
  end
protected
  def items_scope
    Item
  end
  def find_items
    items_scope.find(item_ids)
  end
end
class UserItem < Item
  def initialize(user)
    @user = user
  end
  # should I add it here?
protected
  # or here?
  def items_scope
    Item.where(user_id: @user.id).not_anonymous
  end
end
方法覆盖:
def find_items
  items_scope.where(id: item_ids)
end