def limit=(new_limit)
      raise ArgumentError, "negative limit given" if new_limit < 0
      raise ArgumentError, "specified limit exceeds capacity" if new_limit > @capacity

      @position = new_limit if @position > new_limit
      @mark = nil if @mark && @mark > new_limit
      @limit = new_limit
    end
def limit=(new_limit)
      raise ArgumentError, "negative limit given" if new_limit < 0
      raise ArgumentError, "specified limit exceeds capacity" if new_limit > @capacity

      @position = new_limit if @position > new_limit
      @mark = nil if @mark && @mark > new_limit
      @limit = new_limit
    end
Set the limit to the given value. New limit must be less than capacity.
 Preserves limit and mark if they're less than the new limit, otherwise
 sets position to the new limit and clears the mark.

 @param new_limit [Integer] position in the buffer

 @raise [ArgumentError] new limit was invalid