Issue #16746 has been updated by etienne (=C9tienne Barri=E9).


I haven't seen it mentioned in the comments so I just wanted to point out t=
hat the regular method-definition syntax doesn't require semicolons, and is=
 very close to this experiment, given the parentheses are mandatory:

``` ruby
def fib(x) x < 2 ? x : fib(x-1) + fib(x-2) end

# one-line style
def value() @value end
# one-line style 3.0
def value() =3D @value

# one-line style setter
def value=3D(value) @value =3D value end
# not supported in 3.0
def value=3D(value) =3D @value =3D value
```

It doesn't remove the `end` which is the purpose of this feature sorry, but=
 I like it because it keeps the consistency of having `end`, while not usin=
g more punctuation like `;` or `=3D`.

----------------------------------------
Feature #16746: Endless method definition
https://bugs.ruby-lang.org/issues/16746#change-89635

* 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 hop=
e Ruby is endless.

So, I'd like to propose a new method definition syntax.

```ruby
def: value(args) =3D expression
```

As you see, there is no "end".

Examples.

```ruby
def: hello(name) =3D
  puts("Hello, #{ name }")

hello("endless Ruby") #=3D> Hello, endless Ruby
```

```ruby
def: inc(x) =3D x + 1

p inc(42) #=3D> 43
```

```ruby
x =3D Object.new

def: x.foo =3D "FOO"

p x.foo #=3D> "FOO"
```

```ruby
def: fib(x) =3D
  x < 2 ? x : fib(x-1) + fib(x-2)

p fib(10) #=3D> 55
```

Limitations.

* `def: foo x =3D x` is invalid; the parentheses for formal arguments are m=
andatory.
* `private def: foo =3D 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: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>