matz (Yukihiro Matsumoto) wrote in #note-4: > And with whatever name, we need the real-world use-case for a new method. Here is another real-world use-case, from my public.law apps which parse JSON: ``` def insert_subparts(for_i...robb (Robb Shecter)
amcaplan (Ariel Caplan) wrote in #note-13: > matz (Yukihiro Matsumoto) wrote: > ... I have a similar real-world use-case: I use chained `#fetch`s when importing JSON: My code needs the JSON to have the correct attributes and structure, a...robb (Robb Shecter)
amcaplan (Ariel Caplan) wrote: > The Hash#dig method made it easy to access methods safely from a nested hash; I'd like to have something similar for access without error protection, and I'd think the most natural name would be Hash#dig...robb (Robb Shecter)
Thanks everyone, for the discussion. I realize that my original comparison with #dig had a typographical error. Here's a gem implementation, with examples that are correct: https://github.com/dogweather/digbang ``` require 'dig_bang'...robb (Robb Shecter)
``` f = -> x { x + 2 } g = -> x { x * 2 } h = f << g f.arity # => 1 g.arity # => 1 h.arity # => -1 THIS SHOULD BE 1 because h "knows" that it takes exactly 1 argument: h.call # => ArgumentError (given 0, expected 1) ``` La...robb (Robb Shecter)
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....robb (Robb Shecter)
See also "Clarify the error message when calling a method with the wrong number of arguments", https://bugs.ruby-lang.org/issues/9025robb (Robb Shecter)
"(expected: 1, provided: 0)" is excellent. This is a big usability issue. Python's message is similar, and includes the function name: `TypeError: fun() takes exactly 1 argument (0 given)` > I agree that someone not familiar with m...robb (Robb Shecter)