[ruby-core:123152] [Ruby Feature#17398] SyntaxError in endless method
From:
"yui-knk (Kaneko Yuichiro) via ruby-core" <ruby-core@...>
Date:
2025-09-01 03:50:16 UTC
List:
ruby-core #123152
Issue #17398 has been updated by yui-knk (Kaneko Yuichiro).
> Note that private def hello = puts "Hello" does not parse for technical reason.
It's possible.
Patch is https://github.com/yui-knk/ruby/tree/bug_17398.
This change allows single endless method definition with command body as an argument of the method.
Some cases you might be aware are
* `private :m, def hello = puts "Hello"`
* This is SyntaxError because only single argument case is allowed.
* This is same with one command is passed to argument. `obj.m 0, cmd 1, 2` is SyntaxError.
* `private def hello = puts "Hello", "World"`
* This is interpreted as `private def hello = puts("Hello", "World")` not `private (def hello = puts "Hello"), "World"`.
* This is same with one command is passed to argument. `obj.m cmd 1, 2` is interpreted as `obj.m cmd(1, 2)` not `obj.m (cmd 1), 2`.
* `private def hello = puts "Hello" do expr end`
* This is interpreted as `private (def hello = puts "Hello") do expr end` not `private (def hello = puts "Hello" do expr end)`
* This is same with one command is passed to argument. `obj.m cmd 1, 2 do expr end` is interpreted as `obj.m (cmd 1, 2) do expr end` not `obj.m (cmd 1, 2 do expr end)`
----------------------------------------
Feature #17398: SyntaxError in endless method
https://bugs.ruby-lang.org/issues/17398#change-114484
* Author: zverok (Victor Shepelev)
* Status: Closed
----------------------------------------
This works:
```ruby
def foo() = puts("bar")
```
This does not:
```ruby
def foo() = puts "bar"
# ^ syntax error, unexpected string literal, expecting `do' or '{' or '('
```
Is this intentional or accidental? Not sure how it is reasoned.
---Files--------------------------------
allow-command-style-endless-method-def.patch (3.44 KB)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/