Skip to content

Fix joining single line Ruby methods without arguments #211

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

Merged

Conversation

gsamokovarov
Copy link
Contributor

@gsamokovarov gsamokovarov commented Aug 18, 2024

Joining single-line Ruby method without arguments into an endless method definition was not working as the regexp pattern expected the def always to accept parenthesized arguments.

Example:

def foo()
  bar
end

Would be joined to:

def foo() = bar

However, the following, which is the idiomatic way to write Ruby methods without arguments, would not:

def foo
  bar
end

Joining single-line Ruby method _without_ arguments into an endless
method definition was not working as the regexp pattern expected the
`def` always to accept parenthesized arguments.

Example:

```ruby
def foo()
  bar
end

```

Would be joined to:

```ruby
def foo() = bar
```

However, the following, which is the idiomatic way to write Ruby methods
without arguments, would not:

```ruby
def foo
  bar
end
```
@gsamokovarov gsamokovarov force-pushed the join-ruby-methods-without-arguments branch from f4aacf5 to a8370b1 Compare August 18, 2024 19:30
@AndrewRadev
Copy link
Owner

I think at the time when I was experimenting, I tried def foo= bar, which doesn't work, since foo= can be a method name itself. I don't remember if ruby itself didn't work without the brackets back then or if I missed checking def foo = bar, but either way, this seems to work fine 👍. Thanks for putting in the work, especially the tests.

@AndrewRadev AndrewRadev merged commit f72d59c into AndrewRadev:main Aug 19, 2024
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

Successfully merging this pull request may close these issues.

2 participants