Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String#indent not working according to demo 🐛 #179

Open
anithri opened this issue Feb 25, 2015 · 3 comments
Open

String#indent not working according to demo 🐛 #179

anithri opened this issue Feb 25, 2015 · 3 comments

Comments

@anithri
Copy link
Contributor

anithri commented Feb 25, 2015

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"
@trans
Copy link
Member

trans commented Mar 2, 2015

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:

  1. tab becomes the same as tabto.
  2. tab is changed to be slightly different than tabto.
  3. margin gets renamed to trim.
  4. margin becomes a new method handling both tab and tabto, based on :lead option.
  5. tabto becomes an alias for margin (albeit the :lead is inverted, so it works like tab in No. 2)
  6. tab becomes just an alias for indent, 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).

@trans
Copy link
Member

trans commented Mar 2, 2015

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"

@trans
Copy link
Member

trans commented Oct 26, 2016

Unless there are any objections I will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants