[#90865] [Ruby trunk Bug#15499] Breaking behavior on ruby 2.6: rb_thread_call_without_gvl doesn't invoke unblock_function when used on the main thread — apolcyn@...
Issue #15499 has been reported by apolcyn (alex polcyn).
3 messages
2019/01/03
[#90877] [Ruby trunk Bug#15499] Breaking behavior on ruby 2.6: rb_thread_call_without_gvl doesn't invoke unblock_function when used on the main thread — apolcyn@...
Issue #15499 has been updated by apolcyn (alex polcyn).
3 messages
2019/01/03
[#90895] Re: [ruby-alerts:11680] failure alert on trunk-mjit@silicon-docker (NG (r66707)) — Eric Wong <normalperson@...>
ko1c-failure@atdot.net wrote:
4 messages
2019/01/05
[#90896] Re: [ruby-alerts:11680] failure alert on trunk-mjit@silicon-docker (NG (r66707))
— Takashi Kokubun <takashikkbn@...>
2019/01/05
Thanks to explain that.
[#91200] [Ruby trunk Feature#15553] Addrinfo.getaddrinfo supports timeout — glass.saga@...
Issue #15553 has been reported by Glass_saga (Masaki Matsushita).
4 messages
2019/01/21
[#91289] Re: [Ruby trunk Feature#15553] Addrinfo.getaddrinfo supports timeout
— Eric Wong <normalperson@...>
2019/01/26
glass.saga@gmail.com wrote:
[ruby-core:91265] [Ruby trunk Feature#15563] #dig that throws an exception if an key doesn't exist
From:
djo.went@...
Date:
2019-01-25 17:07:34 UTC
List:
ruby-core #91265
Issue #15563 has been reported by 3limin4t0r (Johan Wentholt).
----------------------------------------
Feature #15563: #dig that throws an exception if an key doesn't exist
https://bugs.ruby-lang.org/issues/15563
* Author: 3limin4t0r (Johan Wentholt)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Ruby 2.3.0 introduced `#dig` for *Array*, *Hash* and *Struct*. Both *Array* and *Hash* have `#fetch` which does the same as `#[]`, but instead of returning the default value an exception is raised (unless a second argument or block is given). *Hash* also has `#fetch_values` which does the same as `#values_at`, raising an exception if an key is missing. For `#dig` there is no such option.
My proposal is to add a method which does the same as `#dig`, but instead of using the `#[]` accessor it uses `#fetch`.
This method would look something like this:
```Ruby
module DigWithException
def dig_e(key, *others)
value = fetch(key)
return value if value.nil? || others.empty?
if value.respond_to?(__method__)
value.public_send(__method__, *others)
else
raise TypeError, "#{value.class} does not have ##{__method__} method"
end
end
end
Array.include(DigWithException)
Hash.include(DigWithException)
```
The exception raised is also taken from `#dig` (`[1].dig(0, 1) #=> TypeError: Integer does not have #dig method`). I personally have my issues with the name `#dig_e`, but I haven't found a better name yet.
There are also a few other things that I haven't thought out yet.
1. Should this method be able to accept a block which, will be passed to the `#fetch` call and recursive `#dig_e` calls?
```Ruby
module DigWithException
def dig_e(key, *others, &block)
value = fetch(key, &block)
return value if value.nil? || others.empty?
if value.respond_to?(__method__)
value.public_send(__method__, *others, &block)
else
raise TypeError, "#{value.class} does not have ##{__method__} method"
end
end
end
Array.include(DigWithException)
Hash.include(DigWithException)
```
2. I currently kept the code compatible with the `#dig` description.
> Extracts the nested value specified by the sequence of *key* objects by calling `dig` at each step, returning `nil` if any intermediate step is `nil`.
However, with this new version of the method one could consider dropping the *"returning `nil` if any intermediate step is `nil`"* part, since this would be the more strict version.
```Ruby
module DigWithException
def dig_e(key, *others)
value = fetch(key)
return value if others.empty?
if value.respond_to?(__method__)
value.public_send(__method__, *others)
else
raise TypeError, "#{value.class} does not have ##{__method__} method"
end
end
end
Array.include(DigWithException)
Hash.include(DigWithException)
```
I'm curious to hear what you guys think about the idea as a whole, the method name and the two points described above.
--
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>