[#75225] [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7) — k@...
Issue #12324 has been reported by Kazuki Yamaguchi.
6 messages
2016/04/27
[#78693] Re: [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7)
— Eric Wong <normalperson@...>
2016/12/17
k@rhe.jp wrote:
[#78701] Re: [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7)
— Kazuki Yamaguchi <k@...>
2016/12/17
On Sat, Dec 17, 2016 at 01:31:12AM +0000, Eric Wong wrote:
[#78702] Re: [Ruby trunk Feature#12324] Support OpenSSL 1.1.0 (and drop support for 0.9.6/0.9.7)
— Eric Wong <normalperson@...>
2016/12/17
Kazuki Yamaguchi <k@rhe.jp> wrote:
[ruby-core:74947] [Ruby trunk Feature#12282] Hash#dig! for repeated applications of Hash#fetch
From:
sawadatsuyoshi@...
Date:
2016-04-14 06:56:10 UTC
List:
ruby-core #74947
Issue #12282 has been updated by Tsuyoshi Sawada.
This makes sense only within limited cases, i.e. when the same key never appears at different depths. For example, if you get an error:
~~~ruby
hash.dig!(:foo, :bar, :foo) # => KeyError: Key not found: :foo
~~~
you cannot tell whether the `:foo` at the first depth or the third depth (or both) is missing. In such case, there is not much difference from doing:
~~~ruby
hash[:foo][:bar][:foo] # => NoMethodError: undefined method `[]' for nil:NilClass
~~~
from the point of view of information the error provides. (With `dig!`, all you can tell is that the error was not caused by `:bar`.) I do not see much value in having a method for such limited use case.
----------------------------------------
Feature #12282: Hash#dig! for repeated applications of Hash#fetch
https://bugs.ruby-lang.org/issues/12282#change-58075
* Author: Robb Shecter
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
A new feature for your consideration: #dig! which is to #fetch as #dig is to #[]. For me and maybe many others, Hash#fetch is used much more than Hash#[]. And traversing multiple fetches isn't very convenient nor Ruby-like, e.g.: places.fetch(:countries).fetch(:canada).fetch(ontario).
Here's how it would work:
~~~
places = { countries: { canada: true } }
places.dig :countries, :canada # => true
places.dig! :countries, :canada # => true
places.dig :countries, :canada, :ontario # => nil
places.dig! :countries, :canada, :ontario # => KeyError: Key not found: :ontario
~~~
Here's an implementation and tests: https://gist.github.com/dogweather/819ccdb41c9db0514c163cfdb1c528e2
--
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>