https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-06-20T14:39:40ZRuby Issue Tracking SystemRuby master - Feature #15945: Option to truncate in `String#ljust`, `String#rjust`, and `String#center`https://bugs.ruby-lang.org/issues/15945?journal_id=787342019-06-20T14:39:40Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I do not have any particular pro/con opinion per se as far as the feature itself<br>
is suggested; if anything then I am mostly neutral, perhaps slightly positive as<br>
I can see a (slight?) use case for it - I guess it depends a lot on the particular<br>
style the ruby user at hand uses. I use .center(), and especially .rjust() and<br>
.ljust() a lot in code where I have to print out something onto the terminal, so<br>
padding strings really is useful e. g. for "box layouts", like ASCII tables and<br>
such. I am even using this sometimes before making use of the "unicode box<br>
drawing" elements - so from this point of view, I can understand everyone else<br>
who is working in a somewhat similar way there.</p>
<p>I agree that, while [start, end] position is simple and universal in ruby to use,<br>
it also indeed requires a little bit of thinking. I myself try to write ruby code<br>
in a way as to never have to think, if this can be avoided - that way I don't write<br>
great code, but I just don't have to think a lot, which is quite useful to me; I<br>
can stay lazy that way. So, from that point of view, options to not have to make<br>
me think are great. :)</p>
<p>I assume that one reason why the second suggestion was made was because three parameters<br>
may be a bit more cumbersome to use than two or one. Changing the current behaviour may<br>
have to go past ruby 3.0, if it is added. So the first suggestion may be simpler to<br>
realize.</p>
<p>As for "truncate" versus "trunc" - I think the longer name would be better. While being<br>
short and succinct can be great, in this context the slightly longer way may be better,<br>
as people may have an easier time understanding what it does in a "natural way", e. g.:</p>
<pre><code>trunc: true
</code></pre>
<p>versus</p>
<pre><code>truncate: true
</code></pre>
<p>(At the least if only those two options are given.)</p>
<p>But mostly I am really neutral on this suggestion either way, just commenting on it. :)</p>