From: eregontp@... Date: 2020-04-10T12:20:49+00:00 Subject: [ruby-core:97797] [Ruby master Feature#16746] Endless method definition Issue #16746 has been updated by Eregon (Benoit Daloze). nobu (Nobuyoshi Nakada) wrote in #note-19: > It is not easy to control parsing time warnings, and bothers tests. The exact same applies to pattern matching and yet we added a warning there. Testing/suppressing the warning is an `eval` away. I think it's important for new experimental syntax to warn about it, especially when the right semantics are unclear. My opinion is it should not capture, `def`/`class`/`module` never captured outside scopes and that shouldn't change. ---------------------------------------- Feature #16746: Endless method definition https://bugs.ruby-lang.org/issues/16746#change-85014 * Author: mame (Yusuke Endoh) * Status: Closed * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) ---------------------------------------- Ruby syntax is full of "end"s. I'm paranoid that the ends end Ruby. I hope Ruby is endless. So, I'd like to propose a new method definition syntax. ```ruby def: value(args) = expression ``` As you see, there is no "end". Examples. ```ruby def: hello(name) = puts("Hello, #{ name }") hello("endless Ruby") #=> Hello, endless Ruby ``` ```ruby def: inc(x) = x + 1 p inc(42) #=> 43 ``` ```ruby x = Object.new def: x.foo = "FOO" p x.foo #=> "FOO" ``` ```ruby def: fib(x) = x < 2 ? x : fib(x-1) + fib(x-2) p fib(10) #=> 55 ``` Limitations. * `def: foo x = x` is invalid; the parentheses for formal arguments are mandatory. * `private def: foo = x` is invalid; this method definition cannot be an method argument. A patch is attached. No conflicts. ---Files-------------------------------- endless-method-definition.patch (2.47 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: