Project

General

Profile

Actions

Feature #16746

closed

Endless method definition

Added by mame (Yusuke Endoh) almost 4 years ago. Updated about 3 years ago.

Status:
Closed
Target version:
-
[ruby-core:97652]

Description

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.

def: value(args) = expression

As you see, there is no "end".

Examples.

def: hello(name) =
  puts("Hello, #{ name }")

hello("endless Ruby") #=> Hello, endless Ruby
def: inc(x) = x + 1

p inc(42) #=> 43
x = Object.new

def: x.foo = "FOO"

p x.foo #=> "FOO"
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) endless-method-definition.patch mame (Yusuke Endoh), 04/01/2020 03:26 AM

Related issues 3 (0 open3 closed)

Related to Ruby master - Feature #5054: Compress a sequence of endsRejectedtechnohippy (Yasushi ANDO)Actions
Related to Ruby master - Feature #5065: Allow "}" as an alternative to "end"RejectedActions
Related to Ruby master - Feature #12241: super endRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0