[ruby-core:94256] [Ruby master Feature#16095] 2 Features: remove (simplify) 'new' keyword and Property Shorthand
From:
merch-redmine@...
Date:
2019-08-10 22:22:22 UTC
List:
ruby-core #94256
Issue #16095 has been updated by jeremyevans0 (Jeremy Evans).
D1mon (Dim F) wrote:
> 1) feature: remove 'new' keyword:
> ``` ruby
> A(1,2) # shorter and more comfortable
> ```
`new` is a method, not a keyword. You can already get what you want:
```
module Kernel
private
def A(arg1, arg2)
A.new(arg1, arg2)
end
end
```
Adding constructor methods to `Kernel` for every class would bloat the method namespace. There are also already cases where a `Kernel` method exists with the same name as a core class but has different behavior (e.g. `Kernel#Hash` vs. `Hash.new`), so this change could not be backwards compatible.
> 2) feature: Property Shorthand (like ES6)
Already requested in #5825 and #15192.
> 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
> ```
Already requested in #15236.
----------------------------------------
Feature #16095: 2 Features: remove (simplify) 'new' keyword and Property Shorthand
https://bugs.ruby-lang.org/issues/16095#change-80571
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>