From: josef.simanek@... Date: 2020-04-05T16:18:48+00:00 Subject: [ruby-core:97723] [Ruby master Feature#16746] Endless method definition Issue #16746 has been updated by retro (Josef ��im��nek). To be honest, I'm a little confused if this is serious proposal now, since it probably started as a joke and got some attention already at GitHub pull request (https://github.com/ruby/ruby/pull/2996) with mixed attitude. Anyway for one-line method definitions I like part of https://bugs.ruby-lang.org/issues/5065. It looks "nature" to me since similar syntax is already available for blocks and often is used for one-liners. Ideally scope this syntax only for one-liners. ``` ruby # original def value; @val; end # proposed - is that conflicting one? def value { @val } ``` Alternatively, since the only use-case I have found in this issue is getter having different method and instance variable names, what about to support this out of attr_reader (and all attr_* friends)? ``` ruby # few ideas attr_reader :value, for: :val # reads as -> attribute reader "value" for instance variable "val", probably impossible for multiple definitions on one line attr_reader value: :val # this would support multiple definitions on one line ``` ---------------------------------------- Feature #16746: Endless method definition https://bugs.ruby-lang.org/issues/16746#change-84933 * Author: mame (Yusuke Endoh) * Status: Assigned * 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: