« Back to channel list

#ruby - 01 March 2019

« Back 1 day Forward 1 day »
[00:02:25] jyaworski: has joined #ruby
[00:04:28] laaron: has joined #ruby
[00:08:07] dviola: has joined #ruby
[00:15:16] canton7: has joined #ruby
[00:18:38] AJA4351: has joined #ruby
[00:31:30] bmurt: has joined #ruby
[00:37:45] akem: has joined #ruby
[00:46:37] TiglatePileser: has joined #ruby
[00:47:47] Fusl: has joined #ruby
[00:52:36] faitswulff: has joined #ruby
[01:12:11] blackmesa1: has joined #ruby
[01:20:07] ramfjord: has joined #ruby
[01:20:21] blackmesa1: has joined #ruby
[01:28:05] AJA4350: has joined #ruby
[01:37:33] ansraliant: has joined #ruby
[01:43:19] mangold: has joined #ruby
[02:05:09] Fusl: has joined #ruby
[02:14:50] crankharder: has joined #ruby
[02:18:09] Swyper: has joined #ruby
[02:18:52] jyaworski: has joined #ruby
[02:20:17] Swyper: https://gist.github.com/RickArora/912c923c2f69302544185faae3614a2e
[02:20:44] Swyper: I'm trying to access an array of hash values
[02:20:49] Swyper: using a key, age
[02:22:55] Swyper: my approach is bad, I should be comparing the value
[02:24:59] havenwood: Swyper: Yes, do compare the value. That aside, `:age` and `"age"` aren't the same key.
[02:26:17] havenwood: Swyper: When iterating from a collection and naming the block argument, consider always using the singular form of the collection.
[02:26:29] havenwood: Swyper: So: people.each do |person|
[02:26:57] Swyper: 02_adult_in_group.rb:9:in `>=': comparison of String with 18 failed (ArgumentError)
[02:27:30] Swyper: https://gist.github.com/RickArora/a64384711eaa86470c8225acc4b9046a
[02:27:36] Swyper: ^ new error, updated code
[02:27:56] havenwood: Swyper: (It's not an Array, so `arr` is a bit confusing!)
[02:28:11] Swyper: also I fixed my error
[02:28:15] Swyper: if(!(value.kind_of?(String)))
[02:28:18] Swyper: ^ fixes it
[02:29:12] havenwood: Swyper: It'd be nicer to just check the ages, instead of all values.
[02:29:37] havenwood: Swyper: person[:age]
[02:30:28] havenwood: Swyper: This is a good case for Enumerable#any? too :)
[02:31:35] Swyper: https://gist.github.com/RickArora/a64384711eaa86470c8225acc4b9046a <-- updated code in comments
[02:31:37] Swyper: thank you havenwood
[02:32:04] havenwood: Swyper: You're doing an extra iteration in there.
[02:32:21] havenwood: Swyper: Try just: people.each do |person| ... (without a second #each)
[02:32:48] havenwood: There's no need for |key, value| as you've rewritten iit.
[02:34:16] faitswulff: has joined #ruby
[02:35:20] havenwood: Swyper: Then you might consider: people.any? do |person|
[02:36:25] havenwood: Swyper: Then you can omit the if statement and the `return true` and `return false`.
[02:36:33] Renich: has joined #ruby
[02:52:02] Swyper: https://gist.github.com/RickArora/24253ea360e63e2c89babd6d9bb7401b
[02:52:37] Swyper: output is incorrect atm, false, true, false false
[02:52:45] Swyper: its supposed to true, true, false, false
[02:52:52] Swyper: tho I don't see why
[02:52:57] leftylink: at first was like "WHAT, didn't you already do this in december", but that was the `ordered_vowel_word?` question, phew
[02:53:15] leftylink: if it had been the exact question it would have been very dismaying.
[02:53:23] leftylink: s/exact/exact same/
[02:54:12] leftylink: Swyper: please consider the value of intermediate expressions. for example, use a REPL to see what the value of "aaoeee".split is
[02:54:13] havenwood: Swyper: I think you mean #chars but you have #split.
[02:54:30] havenwood: &>> "aaoeee".split
[02:54:32] rubydoc: # => ["aaoeee"] (https://carc.in/#/r/6e01)
[02:54:37] havenwood: &>> "aaoeee".chars
[02:54:38] rubydoc: # => ["a", "a", "o", "e", "e", "e"] (https://carc.in/#/r/6e02)
[02:55:00] havenwood: I agree with the suggestion to use a REPL!
[02:55:12] ruby[bot]: irb is "interactive ruby", it is part of ruby. You can run ruby code and see results immediately. it's useful for testing code. Also see ?pry, a gem which is a popular alternative to irb.
[02:55:27] ruby[bot]: Pry, the better IRB, provides easy object inspection `ls`, `history`, viewing docs `?`, viewing source `$`, syntax highlighting and other features (see `help` for more). Put `binding.pry` in your source code for easy debugging. Install Pry (https://pryrepl.org/): gem install pry pry-doc
[02:56:52] Swyper: leftylink: I don't see the problem if it was the exact same question, I haven't touched Ruby in a long time so I'm going through some altered versions of the same questions
[02:57:07] Swyper: but yeah I should use pry, thanks
[02:59:31] orbyt_: has joined #ruby
[03:01:50] faitswulff: has joined #ruby
[03:06:35] tdy: has joined #ruby
[03:12:36] tdy1: has joined #ruby
[03:13:01] donofrio: has joined #ruby
[03:14:27] tdy1: has joined #ruby
[03:16:41] tdy1: has joined #ruby
[03:20:15] tdy2: has joined #ruby
[03:20:51] jyaworski: has joined #ruby
[03:30:32] tdy3: has joined #ruby
[03:30:44] Swyper: has joined #ruby
[03:47:27] mangold: has joined #ruby
[03:50:27] blackmesa: has joined #ruby
[03:54:42] donofrio: has joined #ruby
[03:57:01] jyaworski: has joined #ruby
[04:02:24] wolfshappen: has joined #ruby
[04:05:01] jyaworski: has joined #ruby
[04:09:06] braincrash: has joined #ruby
[04:38:14] Fusl: has joined #ruby
[04:42:42] conta: has joined #ruby
[05:01:11] kapil____: has joined #ruby
[05:01:59] Fusl: has joined #ruby
[05:03:09] faitswulff: has joined #ruby
[05:25:07] crankharder: has joined #ruby
[05:28:26] dellavg__: has joined #ruby
[05:45:24] t0xik: has joined #ruby
[05:56:55] tdy: has joined #ruby
[05:59:40] tdy1: has joined #ruby
[05:59:40] rippa: has joined #ruby
[06:03:23] tdy2: has joined #ruby
[06:06:45] tdy2: has joined #ruby
[06:21:31] jyaworski: has joined #ruby
[06:24:59] nwradio: has joined #ruby
[06:27:58] jordanm: has joined #ruby
[06:28:08] sauvin: has joined #ruby
[06:32:05] nwradio: has joined #ruby
[06:44:20] jordanm: has joined #ruby
[06:44:27] reber: has joined #ruby
[06:45:59] tdy3: has joined #ruby
[06:50:11] tdy4: has joined #ruby
[06:51:59] tdy: has joined #ruby
[06:55:16] tdy1: has joined #ruby
[07:00:00] maufart__: has joined #ruby
[07:04:03] faitswulff: has joined #ruby
[07:07:36] ogres: has joined #ruby
[07:22:18] jyaworski: has joined #ruby
[07:33:56] n13z: has joined #ruby
[07:37:16] aupadhye: has joined #ruby
[07:44:57] prestorium: has joined #ruby
[07:54:32] hahuang6|: has joined #ruby
[07:58:51] conta: has joined #ruby
[07:59:06] clemens3_: has joined #ruby
[08:09:56] tdy1: has joined #ruby
[08:12:59] n13z: has joined #ruby
[08:19:05] clemens3_: has joined #ruby
[08:23:32] jyaworski: has joined #ruby
[08:24:09] _whitelogger: has joined #ruby
[08:26:11] dionysus69: has joined #ruby
[08:35:46] akem: has joined #ruby
[08:39:57] bruce_lee: has joined #ruby
[08:41:37] Renich: has joined #ruby
[08:43:01] aupadhye: has joined #ruby
[08:44:20] blackmesa: has joined #ruby
[08:45:15] akem: has joined #ruby
[08:48:32] aupadhye: has joined #ruby
[09:04:54] faitswulff: has joined #ruby
[09:11:15] olspookishmagus: has joined #ruby
[09:13:40] lxsameer: has joined #ruby
[09:43:19] adgtl: has joined #ruby
[09:43:36] al2o3-cr: has joined #ruby
[09:57:28] vondruch: has joined #ruby
[10:00:09] apparition: has joined #ruby
[10:02:22] adgtl: has joined #ruby
[10:03:44] crankharder: has joined #ruby
[10:04:58] lunarkitty: has joined #ruby
[10:05:40] wolfshappen: has joined #ruby
[10:08:39] Mike11: has joined #ruby
[10:10:39] johnny56: has joined #ruby
[10:25:17] chrisco: has joined #ruby
[10:35:04] cisco: has joined #ruby
[10:37:34] wildermind: has joined #ruby
[10:39:47] marmotini_: has joined #ruby
[10:48:38] dellavg__: has joined #ruby
[10:51:55] Ropeney: has joined #ruby
[10:59:01] am0123: has joined #ruby
[11:05:44] faitswulff: has joined #ruby
[11:07:12] al2o3-cr: has joined #ruby
[11:09:53] tuor: has joined #ruby
[11:16:35] beefjoe: has joined #ruby
[11:19:49] conta: has joined #ruby
[11:22:42] jyaworski: has joined #ruby
[11:42:15] deathwishdave: has joined #ruby
[11:43:24] AJA4350: has joined #ruby
[11:45:52] am0123: has joined #ruby
[11:55:40] snowy: has joined #ruby
[11:58:23] conta: has joined #ruby
[11:59:41] jyaworski: has joined #ruby
[12:10:41] tjbp: has joined #ruby
[12:24:40] jyaworski: has joined #ruby
[12:25:15] ldnunes: has joined #ruby
[12:27:39] Blaguvest: has joined #ruby
[12:31:11] al2o3-cr: has joined #ruby
[12:31:15] camilasan: has joined #ruby
[12:31:31] queip: has joined #ruby
[12:37:05] Xiti: has joined #ruby
[12:37:35] themsay: has joined #ruby
[12:40:36] faitswulff: has joined #ruby
[12:46:31] grr12314: has joined #ruby
[12:47:05] grr12314: wtf ruby, string.sum is giving me a different result from string.bytes.sum
[12:47:25] grr12314: for a long string
[12:48:20] grr12314: the difference is 65536...
[12:48:33] grr12314: damn someone used 16bit int wtf
[12:59:14] xrexeon: has joined #ruby
[13:00:06] xrexeon: has joined #ruby
[13:03:13] stryek: has joined #ruby
[13:18:10] laaron: has joined #ruby
[13:19:45] lucasb: has joined #ruby
[13:24:17] snowy: has joined #ruby
[13:25:46] am0123: has joined #ruby
[13:27:53] tjbp: has joined #ruby
[13:48:02] beefjoe: has joined #ruby
[13:50:48] grr12314: this chan isn't too popular is it...
[13:53:19] phaul: You get a fairly quick response if you come in asking for help. If you come in for a rant it depends. Sometimes ppl are not in the mood
[13:57:18] grr12314: thats cool. it seems "working as intended" https://www.rubydoc.info/stdlib/core/String:sum
[13:57:47] grr12314: i wonder how many people fall into that trap tho
[14:05:18] bmurt: has joined #ruby
[14:05:31] deathwishdave: has joined #ruby
[14:13:56] aupadhye: has joined #ruby
[14:17:47] alem0lars: has joined #ruby
[14:18:35] gensym: has joined #ruby
[14:20:00] gensym: hi, n00b question: i want something like .dig() or safe navigation &. for strings as hashkeys. Both dig() and .& only works for :keys as hashkeys. Any idea?
[14:20:55] gensym: something like h = {'foo'=>'bar'}; and h&.['foo']&.['baz']
[14:22:05] phaul: &>> {'a' => { 'b' => { 'c' => 1 } } }.dig('a', 'b', 'c')
[14:22:07] rubydoc: # => 1 (https://carc.in/#/r/6e1x)
[14:24:15] phaul: gensym: ^
[14:25:38] gensym: @phaul: okay, my problem ist following:
[14:25:46] gensym: &>> {'a' => { 'b' => { 'c' => 1 } } }.dig('a', 'b', 'c', 'd')
[14:25:46] rubydoc: stderr: -e:2:in `dig': Integer does not have #dig method (TypeError) (https://carc.in/#/r/6e1y)
[14:28:24] phaul: dig works under the assumption that the hash either contains right data. the last level there contains 1, which is not right for looking up 'd' in it.
[14:28:37] phaul: s/either//
[14:29:22] phaul: &>> {'a' => { 'b' => { 'c' => {} } } }.dig('a', 'b', 'c', 'd')
[14:29:22] rubydoc: # => nil (https://carc.in/#/r/6e1z)
[14:30:02] phaul: so question there is why the value 1 under 'c' if you expect hash under it (to look up 'd') ?
[14:30:44] jyaworski: has joined #ruby
[14:31:27] gensym: maybe i dont know the structure :/
[14:32:44] ams__: has joined #ruby
[14:43:04] SeepingN: has joined #ruby
[14:48:55] salasrod: has joined #ruby
[14:49:59] bmurt: has joined #ruby
[14:51:55] alem0lars: has joined #ruby
[14:56:23] kapil____: has joined #ruby
[14:59:20] Rapture: has joined #ruby
[15:01:11] gnufied: has joined #ruby
[15:04:59] skryking: has joined #ruby
[15:15:06] polishdub: has joined #ruby
[15:22:05] jcalla: has joined #ruby
[15:23:37] jyaworski: has joined #ruby
[15:23:56] jcarl43: has joined #ruby
[15:23:56] reber: has joined #ruby
[15:30:48] laaron: has joined #ruby
[15:31:40] jcarl43: has joined #ruby
[15:36:27] jyaworski: has joined #ruby
[15:51:27] moei: has joined #ruby
[16:00:56] AJA4351: has joined #ruby
[16:06:18] jyaworski: has joined #ruby
[16:10:01] Dbugger: has joined #ruby
[16:11:06] galaxie: has left #ruby: ()
[16:12:01] conta1: has joined #ruby
[16:21:53] Sylario: has joined #ruby
[16:22:40] Rapture: has joined #ruby
[16:29:45] whathappens: has joined #ruby
[16:32:19] cisco: has joined #ruby
[16:33:07] tdy1: has joined #ruby
[16:50:40] orbyt_: has joined #ruby
[16:56:21] FastJack: has joined #ruby
[16:59:40] gix: has joined #ruby
[17:04:02] snowy: has joined #ruby
[17:05:23] kitikonti: has joined #ruby
[17:09:53] gix: has joined #ruby
[17:10:06] jottr: has joined #ruby
[17:10:41] [Butch]: has joined #ruby
[17:12:31] blackmesa: has joined #ruby
[17:13:49] duderonomy: has joined #ruby
[17:16:22] mniip: has joined #ruby
[17:28:41] amosbird: has joined #ruby
[17:28:48] amosbird: Hello, can anyone help me with this https://la.wentropy.com/P1gC?
[17:28:56] amosbird: I have no idea how to read ruby
[17:29:08] amosbird: what directory does this ruby script need?
[17:29:20] Dbugger: has joined #ruby
[17:30:33] leftylink: I see that you are asking about a directory. That probably means https://ruby-doc.org/core-2.5.1/Dir.html#method-c-5B-5D is a good starting point for the answer
[17:31:42] amosbird: benchs = `./#{Dir["bench*"].first} l`.split("\n")
[17:31:45] amosbird: what does this mean?
[17:33:08] amosbird: ok, i get it
[17:33:36] leftylink: for backticks, see https://ruby-doc.org/core-2.6.1/Kernel.html#method-i-60
[17:40:14] Swyper: has joined #ruby
[17:47:47] nowhere_man: has joined #ruby
[17:51:05] FastJack: has joined #ruby
[18:07:27] c-c: has joined #ruby
[18:07:38] c-c: Evening ghosts
[18:08:20] c-c: time to continue monologue on writing a proc with named pipe message box
[18:09:02] c-c: last weekkie I got this far, its only about 10% pseudocode https://gist.github.com/csmr/5c0da68094e8112c4624f457f180be24
[18:09:53] c-c: so next I will attempt to have a gold spike, ie no-brains procs with message boxes using the fastest IPC method (outside shared memory)
[18:24:41] rippa: has joined #ruby
[18:26:19] t0x: has joined #ruby
[18:27:29] amosbird: hi, how can I make ruby write to stdout and to a log file ?
[18:27:57] havenwood: amosbird: Are you familiar with Logger?
[18:28:14] amosbird: I don't know ruby at all
[18:28:42] rubydoc: https://ruby-doc.org/stdlib-2.6/libdoc/logger/rdoc/Logger.html
[18:29:31] havenwood: c-c: I'm curious - what's the advantage over communicating over say a UNIXSocket?
[18:29:50] amosbird: hmm, too complicated
[18:29:54] amosbird: I'll use tee instead
[18:30:31] havenwood: amosbird: That works!
[18:32:07] c-c: havenwood: if the socket takes 25 ms, named pipe takes 4 ms
[18:32:19] havenwood: c-c: mmmm, interesting...
[18:32:26] c-c: (shared memory takes like 0,1 ms)
[18:32:36] c-c: also, I'm just learning stuff
[18:32:49] havenwood: c-c: I used to have a gem for IPC: https://github.com/havenwood/ifuture#usage
[18:32:57] ua: has joined #ruby
[18:33:22] havenwood: inter-process futures
[18:35:05] havenwood: amosbird: I just meant, no issue with just using tee. The simplest thing that can possibly work is a fine choice.
[18:35:12] alem0lars: has joined #ruby
[18:36:31] havenwood: amosbird: Consider `warn` in place of `STDERR.puts`
[18:36:48] c-c: yeah my approach is all wrongf
[18:37:35] c-c: this looks clean https://github.com/phlipper/ichannel/blob/master/lib/ichannel.rb
[18:38:41] havenwood: c-c: yeah, it seemed like a nice approach to me too
[18:39:22] havenwood: c-c: I should maybe undeprecate ifuture now that Rob has revived ichannel.
[18:39:54] c-c: yeah I started this rewrite because I kept having problems opening the pipe correctly, Should just open both ends at once and pass the handles around.
[18:41:38] Axsuul: has joined #ruby
[18:51:01] sameerynho: has joined #ruby
[18:55:07] cnsvc_: has joined #ruby
[19:07:11] jottr: has joined #ruby
[19:16:11] postmodern: has joined #ruby
[19:18:45] cthulchu: has joined #ruby
[19:19:10] barg: would anybody use byebug over pry-byebug, if so, why?
[19:19:33] barg: like, is pry-byebug meant to be an improvement like byebug with pry features?
[19:21:36] tdy1: has joined #ruby
[19:22:29] Renich: has joined #ruby
[19:28:04] havenwood: barg: The reason to use pry-byebug is all of pry's features.
[19:28:25] havenwood: barg: The reason to use byebug alone is for the additional features that pry-byebug doesn't support.
[19:28:36] themsay: has joined #ruby
[19:31:36] nchambers: has joined #ruby
[19:33:00] cnsvc_: has joined #ruby
[19:33:40] agent_white: has joined #ruby
[19:34:48] ravenous_: has joined #ruby
[19:37:15] Sembei: has joined #ruby
[19:38:22] Renich_: has joined #ruby
[19:40:58] cthulchu_: has joined #ruby
[19:43:11] amosbird: how can I merge these two list
[19:43:14] amosbird: apps = Dir["bench*absl_Hash"].sort.uniq
[19:43:16] amosbird: apps = Dir["bench*robin_hood_hash"].sort.uniq
[19:44:38] leftylink: amosbird: if you just want to concatenate them, not caring about uniqueness, the + operator will do. if you want to deduplicate, try | (or I guess you could + and then .uniq, but unnecessary!)
[19:44:56] amosbird: place | at wher
[19:45:22] leftylink: &>> [ ["a", "b"] + ["b", "c"], ["a", "b"] | ["b", "c"] ]
[19:45:23] rubydoc: # => [["a", "b", "b", "c"], ["a", "b", "c"]] (https://carc.in/#/r/6e5o)
[19:45:29] leftylink: the two possible things you might want to do
[19:47:01] amosbird: apps = Dir[["bench*absl_Hash"] | ["bench*robin_hood_hash"]].sort.uniq
[19:47:05] amosbird: this doesn't work
[19:48:05] duderono_: has joined #ruby
[19:48:26] leftylink: of course it doesn't, but that wasn't what you were asking
[19:48:42] leftylink: you were asking how to combine the results of the two Dir calls, not their inputs
[19:48:54] amosbird: leftylink: ok
[19:57:11] laaron: has joined #ruby
[20:03:21] havenwood: amosbird: Dir["bench*{absl_H,robin_hood_h}ash"]
[20:05:01] jyaworski: has joined #ruby
[20:16:14] laaron: has joined #ruby
[20:17:19] djdduty: has joined #ruby
[20:25:02] AJA4350: has joined #ruby
[20:37:56] gravitation: has joined #ruby
[20:39:12] wilbert: has joined #ruby
[20:56:47] ravenousmoose: has joined #ruby
[21:06:49] Puppet`: has joined #ruby
[21:07:26] cd: has joined #ruby
[21:09:50] Fernando-Basso: has joined #ruby
[21:17:24] tdy: has joined #ruby
[21:35:23] Fusl: has joined #ruby
[21:39:27] cnsvc_: has joined #ruby
[21:51:47] themsay: has joined #ruby
[21:53:17] AJA4350: has joined #ruby
[22:07:16] Swyper: has joined #ruby
[22:13:17] bmurt: has joined #ruby
[22:33:58] orbyt_: has joined #ruby
[22:36:42] jyaworski: has joined #ruby
[22:42:56] wilbert: has joined #ruby
[22:44:04] x0F_: has joined #ruby
[22:44:42] gmcintire_: has joined #ruby
[22:44:53] ctp___: has joined #ruby
[22:45:08] JJonah_: has joined #ruby
[22:45:13] darthThorik_: has joined #ruby
[22:45:15] sparch: has joined #ruby
[22:45:32] khalella_: has joined #ruby
[22:45:33] hsiktas_: has joined #ruby
[22:45:33] KnownSyntax_: has joined #ruby
[22:45:33] Mutsuhito_: has joined #ruby
[22:45:42] iamdevnul_: has joined #ruby
[22:45:53] ec\: has joined #ruby
[22:45:58] jnix_: has joined #ruby
[22:46:17] timeless_: has joined #ruby
[22:46:31] lewix_: has joined #ruby
[22:48:05] jcalla: has joined #ruby
[22:49:31] nowhereman: has joined #ruby
[22:51:15] tpendragon_: has joined #ruby
[22:51:26] Spitfire_: has joined #ruby
[22:52:08] SegFaultAX_: has joined #ruby
[22:53:22] dumptruckman: has joined #ruby
[22:54:15] agent_white: has joined #ruby
[22:54:47] varesa_: has joined #ruby
[22:55:13] Renich_: has joined #ruby
[22:58:33] Axsuul: has joined #ruby
[23:01:44] teej: has joined #ruby
[23:01:56] SCHAPiE: has joined #ruby
[23:04:54] SolarAquarion: has joined #ruby
[23:05:57] t0x: has joined #ruby
[23:06:37] shenghi: has joined #ruby
[23:23:18] Darmani: has joined #ruby
[23:25:17] jyaworski: has joined #ruby
[23:25:37] Darmani: Hi everyone! I'm trying to write a comparison operator for my object class that compares the grade it holds to another grade. It's supposed to account for the "+" and "-" in the string.
[23:25:39] Darmani: https://gist.github.com/mfifth/46fb313965ab679409dedf1765232e52
[23:26:02] Darmani: I'm not sure I know what I'm doing because I keep getting an argument error saying I'm providing an argument but I don't know what that means.
[23:26:29] baweaver: Darmani: How do blocks work in Ruby?
[23:26:55] baweaver: Give you a hint: they're not parens in this case.
[23:27:08] baweaver: Also that scan isn't going to do what you think it will.
[23:27:15] Darmani: Man it's been a while since I've been here.
[23:27:28] Darmani: baweaver: yeah I know I just wasn't sure what the correct method was.
[23:27:33] baweaver: Also it's `grade`, not `string`
[23:27:36] Darmani: Just trying to write it out in pseudocode if you will.
[23:27:57] baweaver: psuedo code might not run so well in Ruby :P
[23:28:13] Darmani: baweaver: Well I know what I'm trying to do just need to get the syntax right.
[23:28:15] baweaver: also `sort_by` only works on Enumerable types.
[23:28:29] baweaver: Is the grade a string or what is it?
[23:28:40] baweaver: If it's an array you might want to call it grades instead.
[23:28:44] Darmani: Grade is just a ruby object class. It holds a string that you can read.
[23:28:48] baweaver: and also split the string
[23:29:08] baweaver: Line 5 though, that's a string?
[23:29:18] Darmani: Well the goal here is so that if you had an array of "Grades" you could call sort on the array and it would properly sort them by the string it contains.
[23:29:37] Darmani: I guess we could call it value. I just called it string.
[23:29:42] baweaver: What's an example of input?
[23:29:46] baweaver: and the expected output?
[23:30:23] Darmani: Well you could put in a string and it would output an Object with that "grade" in it.
[23:30:42] baweaver: What's in the string?
[23:30:53] baweaver: and what's a greade
[23:31:02] baweaver: Anything doesn't really help.
[23:31:04] Darmani: "A", "B-", "C"
[23:31:09] baweaver: There we go
[23:31:28] baweaver: and you want to sort by those grades lexically? (alphabetical order)
[23:31:42] Darmani: yeah I think so. And by the + or -
[23:31:49] Darmani: So that's why I thought scan.
[23:31:54] baweaver: You want sort, which yields two items
[23:32:11] baweaver: collection.sort { |a, b| ... }
[23:32:22] Darmani: Wait why do I want two
[23:32:27] baweaver: sort_by if you have a property available
[23:32:49] baweaver: I wonder...
[23:33:06] baweaver: &>> %w(A+ F B- B B+).sort
[23:33:08] rubydoc: # => ["A+", "B", "B+", "B-", "F"] (https://carc.in/#/r/6e76)
[23:33:36] Darmani: Well I do have a property available so wouldn't it be sort_by?
[23:33:45] baweaver: So it'll get the letter right, you just have to give a higher priority to the +.
[23:33:46] Darmani: Line 5 right?
[23:33:46] baweaver: which property?
[23:33:56] baweaver: No, that's what you're sorting
[23:34:01] baweaver: each item would have a property
[23:34:27] Darmani: So how do we give priority to the +?
[23:34:57] Darmani: A regex I would assume.
[23:36:33] Darmani: I guess I'm not sure how to include a way for the Array.sort method to be included in my class. Line 12 obviously isn't the way to do it.
[23:36:41] leftylink: think of this as primarily sorting by the letter, then secondarily sorting by the modifier (+, -, nothing)
[23:36:43] bambanx: has joined #ruby
[23:37:06] leftylink: sorting primarily by criterion 1 and secondarily by criterion 2 is achieved by having sort_by 's block yield a two-element array
[23:37:17] baweaver: Make a map for the second property
[23:37:27] dviola: has joined #ruby
[23:37:35] Darmani: So I mutate the array twice
[23:37:41] Darmani: One for letters and then again for symbols.
[23:37:45] baweaver: yeah, sort_by would work here, not thinking clearly.
[23:38:16] Darmani: So it is sort_by I knew it.
[23:38:21] Darmani: okay let me play with it a bit.
[23:38:36] Darmani: leftylink: thanks ^_^
[23:38:38] leftylink: for example, [1, 10, 2, 40, 4, 13].sort_by { |x| [x.digits.sum, x] }
[23:38:45] leftylink: &>> [1, 10, 2, 40, 4, 13].sort_by { |x| [x.digits.sum, x] }
[23:38:46] rubydoc: # => [1, 10, 2, 4, 13, 40] (https://carc.in/#/r/6e79)
[23:39:03] leftylink: as you can see, it has sorted primarily by the digital sum and secondarily by the magnitude of the number
[23:39:39] _whitelogger: has joined #ruby
[23:39:52] Darmani: I need to look at the sort_by documentation.
[23:41:50] leftylink: sort_by will not explicitly mention what's going on when you have its block yield an array, but it is the consequence of the fact of how arrays compare against each other
[23:42:04] leftylink: nevertheless, yes, reading about sort_by is still encouraged
[23:42:15] Darmani: Bear with me guys
[23:42:21] Darmani: What's the correct way to write line 12?
[23:43:45] havenwood: barg: For example, if you want to go right into exploring the stack without executing any code. You can just give the filename with `byebug` like `byebug hola.rb`. I'd image most folk use pry-byebug since Pry is popular.
[23:44:01] leftylink: if it is a requirement tha tyou use <=>, I suppose you'd have to say `something <=> other.something`, where the `something` is what we discussed above w/ the two-element array
[23:44:32] leftylink: in which case sort_by would not come into play
[23:45:15] leftylink: sort_by would only come into play if we have something like `%w(A+ F B- B B+).sort_by { |g| ... }`
[23:45:20] Darmani: leftylink: It's not a requirement. I've just never done this before.
[23:47:13] havenwood: &>> perfect = 'A+'; [perfect, perfect.next, perfect.chr.next, perfect.chr.next+?-, perfect.chr.next.next.next.next.next]
[23:47:14] rubydoc: # => ["A+", "B+", "B", "B-", "F"] (https://carc.in/#/r/6e7c)
[23:50:43] leftylink: well, at least the benefit of using <=> would be that you'd be able to get the other comparison ops for free!
[23:51:00] leftylink: so, given that it is not required, that would be the deciding factor of whether to use it