Issue #16095 has been updated by jwmittag (J=F6rg W Mittag).


Please, do not mix requests for multiple unrelated features in one feature =
request. It makes it impossible to properly address them. For example, what=
 should happen with this feature request if one feature gets accepted and o=
ne gets rejected?

Also, in this particular case, all three of the features you request have b=
een requested before, but it is impossible to properly mark this feature re=
quest as a duplicate because which of the three duplicated features should =
you close it as a duplicate of?

D1mon (Dim F) wrote:
> **common use:**
> ``` ruby
> class A
>   def initialize(arg1, arg2)
>     @arg1 =3D arg1
>     @arg2 =3D arg2
>   end
> end
> A.new(1,2)
> ```
> =

> 1) feature: remove 'new' keyword:
> ``` ruby
> A(1,2) # shorter and more comfortable
> ```

There is no such thing as a `new` keyword in Ruby. [It's just a method like=
 any other method.](https://ruby-doc.org/core/Class.html#method-i-new) If y=
ou want to remove this method, you need to propose a different method as a =
replacement. For example, like this:

```ruby
class Class
  alias_method :foo, :new
end

A.foo(1, 2)
```

or something like this

```ruby
class Class
  alias_method :[], :new
end

A[1, 2]
```

or something like this

```ruby
class Class
  alias_method :call, :new
end

A.(1, 2)
```

It seems you simply want a method with the same name as the constant refere=
ncing the class. You can easily do that, too:

```ruby
def A(...)
  A.new(...)
end

A(1, 2)
```
 =

There is no need for a new language feature, you can easily implement what =
you want using the existing language features.

Note that this would completely break backwards-compatibility because there=
 are already existing methods [`Kernel#Array`](https://ruby-doc.org/core/Ke=
rnel.html#method-i-Array), [`Kernel#Complex`](https://ruby-doc.org/core/Ker=
nel.html#method-i-Complex), [`Kernel#Float`](https://ruby-doc.org/core/Kern=
el.html#method-i-Float), [`Kernel#Hash`](https://ruby-doc.org/core/Kernel.h=
tml#method-i-Hash), [`Kernel#Integer`](https://ruby-doc.org/core/Kernel.htm=
l#method-i-Integer), [`Kernel#Rational`](https://ruby-doc.org/core/Kernel.h=
tml#method-i-Rational), and [`Kernel#String`](https://ruby-doc.org/core/Ker=
nel.html#method-i-String) in the core library, as well as [`Kernel#BigDecim=
al`](https://ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/Kernel.html#method-=
i-BigDecimal) in the standard library and probably others in third-party li=
braries and gems.

In fact, the idiom "method with the same name as the class" *already* has a=
 very specific meaning and you are completely breaking that meaning.

> 2) feature: Property Shorthand (like ES6)
> ``` ruby
> class A
>   def initialize(arg1, arg2)
>     # shorter and more comfortable
>     @arg1, @arg2
>     # or this:
>     @arg1
>     @arg2
>   end
> end
> ```

This completely breaks backwards-compatibility, since `@arg2` already has a=
n existing meaning: dereference and evaluate `@arg2`. It would basically ma=
ke it impossible to write simple getters, e.g.:

```ruby
def visible?
  @is_visible
end
```

Just as a historical data point, I would like to point out that up until Ru=
by 1.8.7, it was possible to write

```ruby
class A
  define_method(:initialize) do |@arg1, @arg2| end
end
```

and I have never seen it used even *once*. That is an indicator as to how i=
mportant the Ruby community sees such a feature: even when it existed, nobo=
dy used it.

> So as not to duplicate the code (words). May need to do some other syntax=
 or character (:arg1, \^arg1, %arg1, ...)

At least one, maybe two, of these conflict with existing syntax.

----------------------------------------
Feature #16095: 2 Features: remove (simplify) 'new' keyword and Property Sh=
orthand
https://bugs.ruby-lang.org/issues/16095#change-82891

* Author: D1mon (Dim F)
* Status: Open
* Priority: Normal
* Assignee: =

* Target version: =

----------------------------------------
**common use:**
``` ruby
class A
  def initialize(arg1, arg2)
    @arg1 =3D arg1
    @arg2 =3D arg2
  end
end
A.new(1,2)
```

1) feature: remove 'new' keyword:
``` ruby
A(1,2) # shorter and more comfortable
```


2) feature: Property Shorthand (like ES6)
``` ruby
class A
  def initialize(arg1, arg2)
    # shorter and more comfortable
    @arg1, @arg2
    # or this:
    @arg1
    @arg2
  end
end
```


So as not to duplicate the code (words). May need to do some other syntax o=
r character (:arg1, \^arg1, %arg1, ...)

can also be applied to other types.

Hash example:
``` ruby
a =3D 1
b =3D 2
h =3D {a:a,b:b} # common use
h =3D {a,b} # new syntax or {%a,%b} - any syntax of your choice
```







-- =

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>