From: kachick1@... Date: 2015-12-12T04:37:58+00:00 Subject: [ruby-dev:49431] [Ruby trunk - Feature #11688] Struct and OpenStruct will be able to chain the Hash#dig Array#dig Issue #11688 has been updated by Kenichi Kamiya. Nobuyoshi Nakada wrote: > As those two classes were not parts of [Feature #11643], they are not rejected nor discussed. > `Struct#dig` should be at least, IMHO. > > > [patch](https://github.com/ruby/ruby/pull/1097) > > I feel that an argument of `OpenStruct#dig` should not raise an exception until it is used, as well as `Array` and `Hash`. > > ~~~ruby > [].dig("foo") #=> no implicit conversion of String into Integer (TypeError) > [].dig(1, "foo") #=> nil > OpenStruct.new.dig(0) #=> undefined method `to_sym' for 0:Fixnum (NoMethodError) > ~~~ > > It may be too strict though. > How do you think? Sorry for the late reply! >nobu Thanks for your improvemets! And I'm sorry to bother you, I forgot to adjust arity as https://github.com/ruby/ruby/commit/482530680c18ea2e44c3300c6f323fabc3bd55f7#diff-f0ac5119f74bfda273347c9925e910d7R226 >It may be too strict though. How do you think? At first, I felt its better to raise an error as `Array#dig given a non index` and `OpenStruct#dig given a non method name`. But since I read https://bugs.ruby-lang.org/issues/11762, I think returning nil is reasonable when the nested receiver respond to #dig. >Matz Thanks to contain both #dig into Ruby 2.3, I'll enjoy! ---------------------------------------- Feature #11688: Struct and OpenStruct will be able to chain the Hash#dig Array#dig https://bugs.ruby-lang.org/issues/11688#change-55487 * Author: Kenichi Kamiya * Status: Closed * Priority: Normal * Assignee: ---------------------------------------- Struct and OpenStruct are rejected with #dig? I couldn't get from [Feature #11643] [patch](https://github.com/ruby/ruby/pull/1097) ---Files-------------------------------- bm_dig.rb (1.88 KB) -- https://bugs.ruby-lang.org/