[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
SXNzdWUgIzE4MjI4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku
11 messages
2021/09/27
[ruby-core:105263] [Ruby master Feature#14579] Hash value omission
From:
"shugo (Shugo Maeda)" <noreply@...>
Date:
2021-09-15 08:54:36 UTC
List:
ruby-core #105263
Issue #14579 has been updated by shugo (Shugo Maeda).
duerst (Martin D=FCrst) wrote in #note-25:
> Ah, so `{if:}` means something close to `{if: local_variable_get(:if)}` a=
nd '{self:}` means something close to `{self: local_variable_get(:self)}` (=
and NOT `{self: self}`). =
Yes.
Technically speaking, `send(:if)` is used instead of local_variable_get if =
the local variable is not defined.
> Not sure we need this, but also not sure it hurts.
In the meeting just after RubyKaigi, someone pointed out that `{if:}[:if]` =
is faster than `binding.local_variable_get(:if)`.
```
excelsior:ruby$ cat bm.rb
require "benchmark"
Benchmark.bmbm do |b|
->(if:) {
b.report("binding.local_variable_get") do
10000.times do
binding.local_variable_get(:if)
end
end
b.report("new hash syntax") do
10000.times do
{if:}[:if]
end
end
}.call(if: 123)
end
excelsior:ruby$ ./ruby bm.rb
Rehearsal --------------------------------------------------------------
binding.local_variable_get 0.005680 0.000211 0.005891 ( 0.005889)
new hash syntax 0.001817 0.000136 0.001953 ( 0.001965)
----------------------------------------------------- total: 0.007844sec
user system total real
binding.local_variable_get 0.003668 0.000094 0.003762 ( 0.003763)
new hash syntax 0.000829 0.000162 0.000991 ( 0.001042)
```
----------------------------------------
Feature #14579: Hash value omission
https://bugs.ruby-lang.org/issues/14579#change-93673
* Author: shugo (Shugo Maeda)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
How about to allow value omission in Hash literals:
```ruby
x =3D 1
y =3D 2
h =3D {x:, y:}
p h #=3D> {:x=3D>1, :y=3D>2}
```
And in keyword arguments:
```ruby
def login(username: ENV["USER"], password:)
p(username:, password:)
end
login(password: "xxx") #=3D> {:username=3D>"shugo", :password=3D>"xxx"}
```
---Files--------------------------------
hash_value_omission.diff (619 Bytes)
-- =
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>