From: Ruby-Lang@... Date: 2019-12-01T07:58:11+00:00 Subject: [ruby-core:96041] [Ruby master Feature#16095] 2 Features: remove (simplify) 'new' keyword and Property Shorthand Issue #16095 has been updated by jwmittag (J�rg 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 one gets rejected? Also, in this particular case, all three of the features you request have been requested before, but it is impossible to properly mark this feature request 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 = arg1 > @arg2 = 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 you 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 referencing 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/Kernel.html#method-i-Array), [`Kernel#Complex`](https://ruby-doc.org/core/Kernel.html#method-i-Complex), [`Kernel#Float`](https://ruby-doc.org/core/Kernel.html#method-i-Float), [`Kernel#Hash`](https://ruby-doc.org/core/Kernel.html#method-i-Hash), [`Kernel#Integer`](https://ruby-doc.org/core/Kernel.html#method-i-Integer), [`Kernel#Rational`](https://ruby-doc.org/core/Kernel.html#method-i-Rational), and [`Kernel#String`](https://ruby-doc.org/core/Kernel.html#method-i-String) in the core library, as well as [`Kernel#BigDecimal`](https://ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/Kernel.html#method-i-BigDecimal) in the standard library and probably others in third-party libraries 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 an existing meaning: dereference and evaluate `@arg2`. It would basically make 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 Ruby 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 important the Ruby community sees such a feature: even when it existed, nobody 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 Shorthand 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 = arg1 @arg2 = 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 or character (:arg1, \^arg1, %arg1, ...) can also be applied to other types. Hash example: ``` ruby a = 1 b = 2 h = {a:a,b:b} # common use h = {a,b} # new syntax or {%a,%b} - any syntax of your choice ``` -- https://bugs.ruby-lang.org/ Unsubscribe: