#ruby - 07 July 2019
« Back 1 day Forward 1 day »
[00:24:14] garyserj: when you pass a key-value pair as an argument to a parameter where the parameter is of the form blah not blah: then is it still called a keyword argument, or just a hash?
[02:37:35] leftylink: wow, well I had not thought about this working before, but it does. if using colons on the definition site and => on the call site
[02:38:40] leftylink: I guess that demystifies how all this handling must go on behind the scenes if you're allowed to use => at call site
[02:46:44] garyserj: leftylink: well, if it converts hash to keyword argument, how are we meant to know if it's passing a hash or a keyword argument, when curly braces are omitted?
[02:59:28] leftylink: that question boils down to "I don't know what this function I'm calling will do with the arguments I'm passing it". that is fundamentally a true statement, we just don't know
[03:00:02] leftylink: unless we have read its code or we believe any contract it professes to adhere to
[03:09:13] leftylink: I see. I must have misunderstood your question then. I apologise for my misunderstanding.
[03:09:26] garyserj: to rephrase. If Ruby is converting hash to keyword argument, how are we meatn to know if Ruby i passsing a hash or a keyword argument to a function when curly braces are omitted?
[03:11:31] leftylink: well then we should try it and see what happens, and then come to an understanding. what are some potential pieces of code that would disprove a hypothesis
[03:12:05] rubydoc: stderr: -e:2:in `f': unknown keyword: c (ArgumentError) (https://carc.in/#/r/76wb)
[03:12:15] rubydoc: stderr: -e:2:in `<main>': non-symbol key in keyword arguments: "c" (ArgumentError) (https://carc.in/#/r/76wc)
[03:16:40] leftylink: ... should I be worried that I cannot get the exact same result on my computer...
[03:17:21] leftylink: well, it is true that I am running 2.6.3 instead of 2.6.0 like carc.in is. I wouldn't have thought that would change that though
[03:17:36] leftylink: with that exact same code, I actually get `wrong number of arguments (given 2, expected 1) (ArgumentError)`
[03:36:10] leftylink: the rule for that one seems obvious though since that was a required positional param
[03:38:10] rubydoc: stderr: -e:2:in `<main>': non-symbol key in keyword arguments: "asdf" (ArgumentError) (https://carc.in/#/r/76wi)
[03:38:33] leftylink: okay, that is actually pretty unfortunate, since it gives a different result on my computer
[12:34:38] havenwood: leftylink: There's some good discussion of where keyword arguments are heading here: https://bugs.ruby-lang.org/issues/14183
[12:35:15] havenwood: leftylink: The change was introduced as part of that ^ initiative, then backed out because it introduced incompatibilities: https://bugs.ruby-lang.org/issues/15658
[12:45:38] leftylink: by the rules of https://docs.ruby-lang.org/en/trunk/syntax/methods_rdoc.html , "When mixing keyword arguments and positional arguments, all positional arguments must appear before any keyword arguments."
[12:47:51] garyserj: does https://docs.ruby-lang.org/ have a table of contents by which i'd find that methods_rdoc.html ?
[12:49:09] garyserj: looks like the 'pages' section is about as close to a table of contents as it gets, ok i guess.
[17:10:22] ngw: I can't solve this exercise https://gist.github.com/ngw/9814e04ac4cc1de08b0b10bf2742eca9
[17:22:29] ngw: omg, I got it... when index is 0 and I do -1 it goes to the last line on the other side