-1

「より良い」とは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

?

4

1 に答える 1