-
Notifications
You must be signed in to change notification settings - Fork 90
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
Ruby: Ternary and case support #23
Conversation
Prevents joining when an else is present.
if end_line_no > 0 | ||
let lines = sj#GetLines(if_line_no, end_line_no) | ||
|
||
let if_line = lines[0] | ||
let end_line = lines[-1] | ||
echo lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is a forgotten debug line? Could you remove it? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Don't worry, I don't have any specific problem with ternary clauses. I'm not sure about the brackets (I use brackets for ternary clauses myself, but it's likely that many people don't), but let's leave them like this and if someone complains, I'll make an option. I'm also okay with the amount of code comments. I have a bunch of comments on various things in the code, but it's mostly quibbles about whitespace or naming. I hope that it won't be too hard to fix them, though if you disagree on any, let me know. I would also appreciate it if you documented the logic in the doc files as well, at the end of this: https://github.com/AndrewRadev/splitjoin.vim/blob/master/doc/splitjoin.txt#L171-236. A single example for the ternary clause and for the case statement will suffice, no need to go into detail -- users can try it out for themselves ;). Other than that, great work! If you could make the changes I pointed out, I'll merge immediately, though don't hesitate to let me know if you disagree with me on any of these points. |
Many thanks for your suggestions - much appreciated! I think I fixed all issues now. You've hit a nerve with your comments on the parens around ternaries. I usually use them for the sake of clarity as well, especially for something like Thanks again for helping out! |
Ruby: Ternary and case support
Thanks again for your work 👍 |
Closes #22
An argument can be made to use the other tense one-line statement for Ruby's
if-else
construct, but that looks more awkward to me than the good old ternary operator (if condition then x else y end
- having anend
lingering around on the line makes this look pretty weird imo)It also handles variable assignments, adding parentheses to the ternary itself, as in:
x = (condition ? true : false)
. Specs are included.There are two triggers: You can invoke splitjoin on single
when
lines, or invoke on thecase
line itself, which calls thewhen
functions on all includedwhen-then
statements, including theelse
case. Confer to the spec file to see what it exactly does (and what it doesn't!)You will notice that one spec example is commented out: For tense
case
switches that only includewhen-then
one-liners, the alignment tools are invoked. This is at the moment however impossible to test. It probably makes no sense to add an alignment tool to the spec dependencies, and I don't think that this experimental spec platform can handle stubbing of theTabular
orAlign
plugin. I left the spec in for referencing purposes. Your decision how you want to handle this of course!If you want I can add more descriptive comments to the code - I haven't done yet because the rest of the code is also not drowned in comments. Code is also relatively simple to follow, but as I said, would be no problem to add more!
Thx for splitjoin (and switch, while we're at it 👍)!