facets
facets copied to clipboard
String#indent not working according to demo :bug:
String#tab is an alias for String#indent. But there are separate tests and demos maintained for both. The tab demo states Unlike #tabto, #tab indents all lines equally regardless of prior indention.
. Followed by:
a = "abc\n xyz".tab(2)
a.assert == " abc\n xyz"
# Actually returns
#> " abc\n xyz"
That one took me a bit to figure out. There was a major transition in these methods starting in mid 2012 and culminating in Jan 2014. In short, it went something like this:
-
tab
becomes the same astabto
. -
tab
is changed to be slightly different thantabto
. -
margin
gets renamed totrim
. -
margin
becomes a new method handling bothtab
andtabto
, based on:lead
option. -
tabto
becomes an alias formargin
(albeit the:lead
is inverted, so it works liketab
in No. 2) -
tab
becomes just an alias forindent
, but is to be deprecated.
It was point No. 1 that actually caused that demo to go afoul. tab
was originally just defined as:
def tab(n)
gsub(/^ */, ' ' * n)
end
I don't recall why I got rid of that altogether now. Guess I thought that was too simple to require a method. Perhaps it would make sense to reintroduce this definition as a new method, or perhaps as a different option of margin
, or even indent
(though that would require changing its interface to (n, opts={})
). What do you think?
In any case, the tab
alias can be deprecated for good now. And while we are at it tabto
as well. I had a vague notion that in the future that I might try to write a new tab
and possibly tabto
that actually handled \t
insertions properly (think of it as indent
meets go's fmt).
P.S. Here's the difference between margin with and without :lead
. We need to make sure this is tested.
a = " abc\n xyz"
a.margin(2)
=> " abc\n xyz"
a.margin(2, :lead=>true)
=> " abc\nxyz"
a.margin(4)
=> " abc\n xyz"
a.margin(4, :lead=>true)
=> " abc\n xyz"
Unless there are any objections I will close this.