False function indentation for latest Ruby 2.1 syntax #190

fgarcia opened this Issue Jan 5, 2014 · 3 comments


None yet
3 participants

fgarcia commented Jan 5, 2014

People who define private functions like this:

def setView(v)
private setView

Can now in Ruby 2.1 write it like this

private def setView(v)

However the current indentation makes this:

    private def setView(v)

It is not only the keyword private, it could be any word since Ruby 2.1. And it seems that some "magic" could be done also with Rubinius


@AndrewRadev AndrewRadev added a commit that referenced this issue Jan 6, 2014

@AndrewRadev AndrewRadev Special rules for `def` as an indent keyword
See #190

Ruby 2.1 makes method definitions return the method name as a symbol.
This means that you could prefix the `def` line with a `private`
and it would make the method private upon definition.

Technically, any method call could be placed before the `def`, but
that's no different than before. The private/protected use case seems
like the most likely one, so this is what we'll handle for now. If it
gets popular to use different class-level methods for method
definitions, we could put a \k\+ instead.

AndrewRadev commented Jan 6, 2014

Huh, didn't realize this was the point of the "method call returns a symbol" change. This "syntax" does have some benefits, I suppose.

I've implemented indenting for this use case. Note that I've only tackled public, protected and private. For now, I'd rather not support "any word" scenarios, since I don't feel they'll be particularly common. If it turns out I'm wrong and people start using all kinds of method calls before def, please reopen (or open a new issue) and I'll see what I can do.

For now, could you let me know if it seems to work for you?

fgarcia commented Jan 10, 2014

wow! you were so much faster than I could test it.

Right now I only want to type private everywhere and the patch solves my problems, but I wonder if people might want to do within a future something like the Python decorators


thanks for the quick response!


AndrewRadev commented Jan 10, 2014

Well, we'll see if this kind of thing becomes popular. If it does, I'm sure there will be a ticket and we can decide whether to change it or not.

For the moment, closing this issue.

fgarcia referenced this issue in bbatsov/rubocop Jan 15, 2014


support for new private syntax #730

dkearns added the indent label Sep 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment