« Back to channel list

#ruby - 31 December 2018

« Back 1 day Forward 1 day »
[00:00:59] al2o3-cr: has joined #ruby
[00:01:09] laaron-: has joined #ruby
[00:01:44] comet23: has joined #ruby
[00:01:56] comet23: where can we submit new language features ideas?
[00:02:27] cschneid: has joined #ruby
[00:04:04] phaul: https://bugs.ruby-lang.org/projects/common-ruby/issues
[00:04:12] garyserj_: has joined #ruby
[00:04:23] comet23: thank you :D
[00:04:30] comet23: we need an unshift operator!
[00:08:03] phaul: what would it do and how would it look like?
[00:10:28] al2o3-cr: &>> class Array; def >>(val) unshift val end end; [1,2,3] >> :foo
[00:10:28] rubydoc: # => [:foo, 1, 2, 3] (https://carc.in/#/r/5vr9)
[00:10:54] al2o3-cr: i like that.
[00:12:56] phaul: hi al2o3-cr
[00:13:15] al2o3-cr: hi phaul ;)
[00:13:57] phaul: check this out:
[00:14:06] phaul: &ri RubyVM
[00:14:06] rubydoc: https://ruby-doc.org/core-2.6/RubyVM.html
[00:14:50] phaul: though the eval is still on 2.5, I need carc.in to be updated first
[00:15:38] phaul: also I *think* it will require actual changes even if small ones, as dissass, ast APIs have changed
[00:16:10] al2o3-cr: phaul: yes, minor changes i think.
[00:16:46] al2o3-cr: &ri Proc#>>
[00:16:46] rubydoc: https://ruby-doc.org/core-2.6/Proc.html#method-i-3E-3E
[00:18:02] NightMonkey: has joined #ruby
[00:18:53] al2o3-cr: i'm sure jhass will update asap.
[00:19:24] catphish: is the behaviour of modifying an array while iterating over it defined?
[00:22:06] catphish: looks like i should probably use Array#delete_if to iterate and allow me to delete items at the same time
[00:23:45] hutch: has joined #ruby
[00:26:05] comet23: yeah the unshift operator will look like >>
[00:26:12] comet23: because the shift operator looks like <<
[00:26:32] phaul: well, the language has an unshift operator then.
[00:27:07] phaul: https://www.tutorialspoint.com/ruby/ruby_operators.htm
[00:27:57] phaul: even though here they claim it's binary shift, really many types implement >> in a way that has nothing to do with bit shifting
[00:32:42] bmurt: has joined #ruby
[00:33:24] spacesuitdiver: has joined #ruby
[00:37:01] d10n-work: has joined #ruby
[00:39:23] blackmesa1: has joined #ruby
[00:59:45] blackmesa1: has joined #ruby
[01:01:01] laaron: has joined #ruby
[01:24:38] Averna: has joined #ruby
[01:32:04] blackmesa1: has joined #ruby
[01:32:52] segy: has joined #ruby
[01:38:05] ellcs: has joined #ruby
[01:38:39] blackmesa1: has joined #ruby
[01:46:07] Nicmavr: has joined #ruby
[01:47:23] jordanm: has joined #ruby
[01:55:35] cschneid: has joined #ruby
[01:57:44] tdy: has joined #ruby
[01:58:02] garyserj_: has joined #ruby
[02:01:12] laaron-: has joined #ruby
[02:03:51] code_zombie: has joined #ruby
[02:19:45] nchambers: has joined #ruby
[02:21:35] BTRE: has joined #ruby
[02:22:13] comet23: So if it has it then why is it not able to be implemented for arrays?
[02:54:31] nowhere_man: has joined #ruby
[02:58:31] patteh: has joined #ruby
[03:01:18] laaron: has joined #ruby
[03:05:08] tdy: has joined #ruby
[03:05:23] Swyper: has joined #ruby
[03:06:38] Swyper: https://gist.github.com/RickArora/0157b604d7bae787c1a287b9801ac912
[03:06:48] Swyper: Can someone help me figure out why my tests are failing ?
[03:11:52] patteh: has joined #ruby
[03:24:28] comet23: Swyper: what exercises are you doing?
[03:25:54] cschneid: has joined #ruby
[03:31:26] jottr: has joined #ruby
[03:31:33] hutch: has joined #ruby
[03:41:57] leftylink: I guess I can still help by commenting on the gist, but apparently that requires a github acct
[03:45:52] Swyper: has joined #ruby
[03:46:37] Swyper: hi, not sure who was talking to me before but I'm doing practice questions from App Academy
[03:47:30] Swyper: https://gist.github.com/RickArora/0157b604d7bae787c1a287b9801ac912
[03:47:46] Swyper: comet23 and leftylink , just looked through logs and it was you two :)
[03:48:11] leftylink: notice that 1: your `ordered_vowel_word?` requires that the word contains all vowels, which the tests do *not* require. 2: "i before e" is a spelling rule not an alphabet order rule
[03:48:46] Swyper: https://dpaste.de/ktM9 if you prefer it on dpaste
[03:50:04] Swyper: 1) Yeah you are right.. I have to think of a way to check for all combinations of vowels in order I guess I could do this with a bunch of OR statements
[03:50:23] Swyper: 2) oh, so it should be AEIOU ?
[03:51:03] Swyper: for 1) I'm thinking there has to be a more efficient way to do this then to pile up a a few OR statements
[03:53:10] Swyper: is there a way to check if a string is a subset of another string ?
[03:53:46] Swyper: way = method in ruby :P
[03:55:26] leftylink: &>> p ["asdf".include?("a"), "asdf".include?("b")]
[03:55:29] rubydoc: # => [true, false] ...check link for more (https://carc.in/#/r/5vt8)
[03:56:12] leftylink: but I think I have misunderstood your question
[03:56:21] leftylink: &>> p ["asdf".include?("as"), "asdf".include?("ad")]
[03:56:21] rubydoc: # => [true, false] ...check link for more (https://carc.in/#/r/5vt9)
[03:59:00] uplime: has joined #ruby
[03:59:00] Swyper: https://dpaste.de/19ox leftylink
[03:59:43] Swyper: https://dpaste.de/Ktxg
[03:59:49] Swyper: ignore the first one it pasted way to much ;x
[04:00:26] Swyper: expected: ["word", "pale", "word", "random", "pry"] got: ["word", "pale", "word", "pry"], why should random even be returned it skips e and i o-o
[04:00:43] leftylink: because: of the vowels that appear (a, o), they are in order.
[04:00:57] leftylink: there is no requirement that any particular vowel must appear
[04:01:02] leftylink: only a requirement on the vowels that do appear
[04:01:10] laaron-: has joined #ruby
[04:01:26] Swyper: # Define a method that accepts an array of words and returns an array of those # words whose vowels appear in order. You may wish to write a helper method: # ordered_vowel_word?
[04:01:36] Swyper: it does say in order in the comments they gave o-o
[04:01:46] leftylink: random's vowels (a, o) appear in order
[04:02:06] leftylink: okra's vowels (o, a) don't
[04:03:45] Swyper: So where my confusion is that to me in order would mean a, e, i ,o, u and a word that skips one of those is not in order, and I'm obviously understanding it wrong but what does in order even mean, then ?
[04:05:22] leftylink: "a word that skips one of those is not in order" - that would be the case if the question asked "the word must contain all the vowels in order"
[04:05:39] leftylink: instead, the question asks "the words vowels must be in order", therefore it only applies to whichever vowels happen to be in the word
[04:06:16] Swyper: okay that makes sense
[04:06:42] Swyper: so my include statement at the moment is not good enough, any ideas on how to improve it to pass the test cases?
[04:07:10] Swyper: or function as it should instead of just pass test cases xD
[04:08:23] baweaver: ACTION wanders in
[04:08:34] braincrash: has joined #ruby
[04:09:04] Swyper: feel free to give me any suggestions :P
[04:10:12] Swyper: I could be lame and just pass the test causes by adding ao to the end of the string but that would lame
[04:10:45] leftylink: well, a lot of the time my process is "how would I do it with pen and paper" and translate that to code. by the by, what *would* be your approach, if you were to be asked to do it with pen and paper?
[04:14:42] Swyper: I guess broke the vowels up into an array, find the index of the array where the first element of the string we are evaluating (the vowels we parsed from the string) appears, discard all elements in the array of vowels prior to where the index was and return false if there is ever a vowel that cannot be found in the array
[04:15:00] Swyper: though I wrote pretty messy so what I wrote above might be hard to follow ^
[04:18:06] al2o3-cr: &>> "random".scan(/[aeiou]/)
[04:18:08] rubydoc: # => ["a", "o"] (https://carc.in/#/r/5vtd)
[04:18:50] Swyper: "random".scan(/[aeiou]/), /[aeiou]/ is regex ?
[04:19:42] al2o3-cr: Swyper: yes.
[04:20:17] al2o3-cr: &>> "random".scan(/[aeiou]/).tap { |vowels| break vowels == vowels.sort }
[04:20:18] rubydoc: # => true (https://carc.in/#/r/5vte)
[04:21:57] Swyper: interesting
[04:22:25] MasterAsia: has joined #ruby
[04:22:44] jottr: has joined #ruby
[04:22:45] Swyper: is there an answer that does not involve regex ? one approach could be to have a bunch of messy if statements nested inside one another
[04:28:42] leftylink: your current approach splits the problem into two parts: 1) get the list of vowels of a word. 2) is this list in order?. your approach to 1 was already working, regardless of whether it uses regex. you were needing to find a way to do part 2. a possible way to do part 2 has now been revealed above, which you can combine with your way to do part 1 if you want.
[04:29:19] leftylink: or, you can come up with your own way to do part 2 if you want
[04:29:39] leftylink: in which case, we ask "how do we figure out whether a list of things is in order?"
[04:31:20] leftylink: the approach you described, if I understood it correctly, does work. you are free to use it or any other way you devise or find
[04:33:42] kapil____: has joined #ruby
[04:34:34] r29v: has joined #ruby
[04:42:37] hutch: has joined #ruby
[04:47:07] havenwood: Swyper: A nit, but it's a bit nicer to use `%w[a e i o u]` instead of `"a i e o u".split` for the same result faster with less memory. In your case it doesn't matter but just mentioning.
[04:47:38] havenwood: Ah, they left. Was gunna suggest they take a look at #each_cons.
[04:49:29] leftylink: (the leaving, I mean)
[04:52:13] ogres: has joined #ruby
[04:56:49] Lytol: has joined #ruby
[05:00:59] laaron: has joined #ruby
[05:14:41] comet23: what is ruby 3 going to be like?
[05:15:04] al2o3-cr: ACTION gets out his crystal ball...
[05:28:16] davidw_: has joined #ruby
[05:30:21] rawrg: has joined #ruby
[05:33:29] patteh: has joined #ruby
[05:33:48] al2o3-cr: for Swyper's next one: Array#reverse, Array#combination, Integer#pred, Enumerable#map and Enumerable#inject
[05:44:51] Swyper: has joined #ruby
[05:44:56] Swyper: def array_product(array, i) counter = 0 array.map = { |int| counter *= int } end
[05:45:20] Swyper: array.map = { |int| int *= counter }is causing me a syntax error any idea why ?
[05:45:49] havenwood: Swyper: get rid of the equal sign in `.map = {`
[05:46:22] havenwood: Swyper: `.map { |int|` instead of `.map = { |int|`
[05:48:04] Swyper: thank you
[05:48:13] Swyper: its returning [0,0,0,0] atm >_>
[05:49:08] baweaver: What happens when you multiply a number by 0?
[05:49:09] baweaver: Also map is the wrong function for this.
[05:51:00] havenwood: &>> require 'prime'; (0..).lazy.select { |n| n.prime? && (n * 9 + 4).prime? }.map { |n| (n + 94).chr }.first 5
[05:51:01] rubydoc: # => (https://carc.in/#/r/5vty)
[05:51:23] havenwood: oh, right - no 2.6 yet :)
[05:51:28] havenwood: &>> require 'prime'; 1.step.lazy.select { |n| n.prime? && (n * 9 + 4).prime? }.map { |n| (n + 94).chr }.first 5
[05:51:28] rubydoc: # => ["a", "e", "i", "o", "u"] (https://carc.in/#/r/5vtz)
[05:52:03] baweaver: How did you find that one?
[05:52:15] havenwood: baweaver: an earlier question was about vowels, and I thought there *must* be a good way to find vowels. >.>
[05:52:27] baweaver: ....how did you figure that out?
[05:52:34] baweaver: They're just conveniently spaced?
[05:52:55] Swyper: return (order_of_vowels.sort.join == order_of_vowels.join)
[05:53:25] Swyper: just compared the sorted vowels with the actual vowels, I can post the whole solution if your curious
[05:53:42] Menteb: has joined #ruby
[05:54:02] havenwood: baweaver: i found an OEIS sequence that matched an offset of the bytes >.>
[05:54:10] baweaver: Interesting.
[05:54:15] Swyper: sort removes duplicates ?
[05:54:39] Swyper: https://dpaste.de/dh9m
[05:54:42] Swyper: ^ solution
[05:55:14] havenwood: baweaver: this is actually the one I wanted to implement, since it aligns with the position of the vowels in the alphabet - but I couldn't figure out what the heck the `a(n)-a(n-1)` part is meant to be.
[05:55:22] havenwood: baweaver: https://oeis.org/A161536
[05:55:59] laaron-: has joined #ruby
[05:56:27] havenwood: It's not the previous binary palindrome or the previous index, so... what is it?
[05:58:20] Swyper: Also sorry I left midway, I use webchat to connect since everything else for mac costs money (textual) or is outdated or to technical for me to use :P
[05:59:30] havenwood: Swyper: LimeChat is the open source project that Textual is based off of: https://github.com/psychs/limechat
[05:59:57] havenwood: Swyper: Or you can build Textual yourself with Xcode: https://github.com/Codeux-Software/Textual
[06:00:55] Swyper: oh thank you
[06:01:12] laaron: has joined #ruby
[06:02:17] havenwood: Swyper: You can catch up on what you miss with the logs: https://irclog.whitequark.org/ruby
[06:02:59] havenwood: Swyper: Many of us use a bouncer like ZNC to replay history to our IRC client for what we missed.
[06:04:47] spacesuitdiver: has joined #ruby
[06:06:17] Swyper: has joined #ruby
[06:06:25] Swyper: yay I'm on through limechat now, thanks
[06:06:36] havenwood: nice, you're welcome
[06:07:00] havenwood: Swyper: https://gist.github.com/havenwood/ab054057884e2abc6a1843d77100e704
[06:07:35] havenwood: Swyper: Just showing you that ^ for the #each_cons bit on line 6. (Ignore the silly way to find the vowels.)
[06:07:45] Swyper: neat thank you
[06:08:00] havenwood: Swyper: It's a handy way to compare each element to the next.
[06:18:13] Swyper: has joined #ruby
[06:22:47] leftylink: Swyper: sort does not remove duplicates
[06:22:50] rippa: has joined #ruby
[06:22:52] leftylink: &>> [1, 1].sort
[06:22:53] rubydoc: # => [1, 1] (https://carc.in/#/r/5vu0)
[06:24:45] akosednar: has joined #ruby
[06:26:15] cschneid: has joined #ruby
[06:33:53] al2o3-cr: so a(n) = smallest integer > a(n-1) that is an odd palindome when written in base 2
[06:34:11] al2o3-cr: i'm struggling with this, i'll tell thee.
[06:38:59] aupadhye: has joined #ruby
[06:41:47] hutch: has joined #ruby
[06:44:43] al2o3-cr: i think i've got it.
[06:57:10] _whitelogger: has joined #ruby
[07:01:10] laaron-: has joined #ruby
[07:05:26] Menteb: has joined #ruby
[07:07:24] uplime: if i have a function (foo(**opts)), is there a way to pass another hash (ie foo **bar), but have it retain the changes afterwards?
[07:08:18] uplime: i could return the updated one, but i'm already returning an array so i thought i'd check
[07:23:19] Swyper: has joined #ruby
[07:25:32] tiff: has joined #ruby
[07:45:10] _whitelogger: has joined #ruby
[08:01:32] Menteb: has joined #ruby
[08:02:30] raulp: has joined #ruby
[08:15:38] patteh: has joined #ruby
[08:22:12] reber: has joined #ruby
[08:31:53] gitness: has left #ruby: ()
[08:45:10] _whitelogger: has joined #ruby
[08:45:38] jottr: has joined #ruby
[08:54:40] dellavg_: has joined #ruby
[08:56:50] cschneid: has joined #ruby
[09:00:11] _whitelogger: has joined #ruby
[09:01:27] laaron: has joined #ruby
[09:04:42] gix: has joined #ruby
[09:09:21] hiroaki: has joined #ruby
[09:11:06] cnsvc: has joined #ruby
[09:21:33] idiocrash: has joined #ruby
[09:47:27] MasterAsia: has joined #ruby
[09:57:55] DTZUZO: has joined #ruby
[10:01:25] laaron-: has joined #ruby
[10:02:16] exchgr`: has joined #ruby
[10:15:35] lxsameer: has joined #ruby
[10:28:18] sandelius: has joined #ruby
[10:39:25] towo: has joined #ruby
[10:47:41] blackmesa1: has joined #ruby
[10:56:19] za1b1tsu: has joined #ruby
[10:57:21] towo: Hey, I'm trying to use Net::SSH::Authentication::Agent to sign something, but when passing the key (for the public key) argument, it apparently expects an OpenSSL::PKey::RSA or similar object. I'm not seeing any way of actually saying "read this string as a public key" anywhere in the whole module. Any hints on how to generate that without reimplementing half the module?
[10:58:15] havenwood: has joined #ruby
[10:59:46] cpallares: has joined #ruby
[11:01:01] laaron: has joined #ruby
[11:04:48] conta: has joined #ruby
[11:06:24] roshanavand: has joined #ruby
[11:27:29] cschneid: has joined #ruby
[11:31:26] sidepocket: has joined #ruby
[11:37:11] thinkpad: has joined #ruby
[11:41:19] vutral1: has joined #ruby
[11:52:31] dviola: has joined #ruby
[12:01:35] laaron-: has joined #ruby
[12:15:36] m0w: has joined #ruby
[12:19:58] AJA4350: has joined #ruby
[12:25:47] Nicmavr: has joined #ruby
[12:32:37] patteh: has joined #ruby
[12:45:50] sandelius: has joined #ruby
[12:46:18] jottr: has joined #ruby
[12:46:39] sandelius: Happy New Year's Eve everyone
[13:05:53] szulak_: has joined #ruby
[13:09:16] EXCHGR: has joined #ruby
[13:11:08] cschneid: has joined #ruby
[13:14:49] cschneid: has joined #ruby
[13:24:10] _whitelogger: has joined #ruby
[13:27:02] cschneid: has joined #ruby
[13:34:57] despai: has joined #ruby
[13:45:08] GodFather: has joined #ruby
[13:47:30] catphish: has left #ruby: ("Leaving")
[13:48:42] agent_white: has joined #ruby
[13:56:28] n01: has joined #ruby
[14:04:21] mostlybadfly: has joined #ruby
[14:04:33] laaron: has joined #ruby
[14:19:53] jgpawletko: has joined #ruby
[14:33:00] MyMind: has joined #ruby
[14:43:12] polishdub: has joined #ruby
[14:45:03] m0w: has joined #ruby
[14:50:44] ellcs: has joined #ruby
[15:03:39] blackmesa1: has joined #ruby
[15:04:49] laaron: has joined #ruby
[15:17:18] d^sh: has joined #ruby
[15:23:09] Rapture: has joined #ruby
[15:45:55] mikecmpbll: has joined #ruby
[15:49:29] d10n-work: has joined #ruby
[15:51:49] szulak_: has joined #ruby
[15:52:32] GodFather: has joined #ruby
[15:52:55] jthomas1: has joined #ruby
[15:55:54] davidw_: has joined #ruby
[16:02:06] Renich: has joined #ruby
[16:04:11] DTZUZO: has joined #ruby
[16:04:28] jthomas2: has joined #ruby
[16:15:50] armyriad: has joined #ruby
[16:16:37] donofrio: has joined #ruby
[16:18:12] Aqo: has joined #ruby
[16:26:00] Dbugger: has joined #ruby
[16:26:01] GodFather: has joined #ruby
[16:29:49] armyriad: has joined #ruby
[16:33:17] mostlybadfly: has joined #ruby
[16:49:10] Mike11: has joined #ruby
[16:51:02] dviola: has joined #ruby
[16:53:02] donofrio: has joined #ruby
[16:58:34] MasterAsia: has joined #ruby
[17:01:36] laaron-: has joined #ruby
[17:07:17] despai: has joined #ruby
[17:07:50] MasterAsia: has joined #ruby
[17:15:10] Swyper: has joined #ruby
[17:15:14] Swyper: https://gist.github.com/RickArora/8f4cf03666bb04a4aafcb3def180cb8a
[17:15:32] Swyper: expected: [24, 12, 8, 6]
[17:15:32] Swyper: got: [24, 288, 27648, 191102976]
[17:16:26] baweaver: Swyper: lead with the problem description
[17:16:29] cthulchu: has joined #ruby
[17:16:38] Swyper: baweaver ?
[17:16:52] Swyper: on the gist it leads with the description :P
[17:17:23] Swyper: https://dpaste.de/QwDJ - dpaste
[17:17:25] baweaver: line 6 doesn't actually make a new list.
[17:17:36] Swyper: oh it just points to the old one? >_>
[17:17:51] Swyper: how do I make a deep copy of that list then ?
[17:18:08] baweaver: You don't need one.
[17:18:25] baweaver: numbers.map instead
[17:19:16] baweaver: Though you could use map.with_index to get the index, which you probably need for this anyways.
[17:20:16] leftylink: doable w/o index, but I guess it depends on how one wants to think about it
[17:20:47] baweaver: One could just invert that singular number considering how multiplication works.
[17:21:16] baweaver: Commutative property wasn't it?
[17:21:22] sameerynho: has joined #ruby
[17:21:29] baweaver: a * b * c == c * b * a
[17:21:35] baweaver: which could be done in any order.
[17:22:00] hutch: has joined #ruby
[17:22:17] baweaver: Swyper: If I add one to a number, how would I undo that?
[17:22:24] Swyper: https://dpaste.de/TsyX - got it working
[17:23:14] Swyper: that's what I'm doing, using commutative property multiplying everything out and then dividing it by whatever number was not supposed to be included in the multiplication
[17:23:37] baweaver: True, but that's not the business of the array_product function
[17:23:45] baweaver: the name becomes a lie by doing that.
[17:24:08] baweaver: That, and you want to likely use sum or reduce instead for getting a product.
[17:25:30] GodFather: has joined #ruby
[17:25:45] baweaver: well, reduce.
[17:26:09] Swyper: True, do you want to show me how it would work using reduce instead of what I'm using now ?
[17:26:27] baweaver: &>> [1, 2, 3].reduce(1) { |accumulator, v| accumulator * v }
[17:26:29] rubydoc: # => 6 (https://carc.in/#/r/5vzg)
[17:26:40] baweaver: &>> [1, 2, 3].reduce(1) { |a, v| a * v }
[17:26:41] rubydoc: # => 6 (https://carc.in/#/r/5vzh)
[17:26:49] baweaver: &>> [1, 2, 3].reduce(1, :*)
[17:26:49] rubydoc: # => 6 (https://carc.in/#/r/5vzj)
[17:27:18] baweaver: This will give you a whole view into how reduce works: https://medium.com/@baweaver/reducing-enumerable-part-one-the-journey-begins-ddc1d4108490
[17:27:29] Swyper: one thing that sort of bugs me is I don't know the difference between map and each
[17:27:40] Swyper: and when to use each one
[17:27:42] baweaver: each only iterates a list
[17:27:51] baweaver: map is used to transform a list and return a new list
[17:31:16] baweaver: Hrm, maybe I should go through a tutorial of basics on how Enumerable works overall and going through usecases of each of the methods.
[17:31:24] baweaver: s/go through/write/
[17:32:36] Swyper: sure I'd love to read that
[17:34:17] tdy: has joined #ruby
[17:45:43] livcd: interesting atm r/elixir has many more readers than r/ruby + r/rails
[17:47:55] KeyJoo: has joined #ruby
[17:49:06] Swyper: jeez, FP is a beast I will go through another day
[17:50:44] Swyper: so I'm trying to create a method that just checks to see if a certain character repeats or not, I know uniq exists - but afaik it modifies the list and uniq? will modify the list aswell or return nil
[17:50:57] Swyper: is there a better approach to accomplishing what I am trying to do ?
[17:53:56] orbyt_: has joined #ruby
[17:54:05] Swyper: the find method looks promising.
[17:54:10] leftylink: there is no uniq? . there is https://ruby-doc.org/core-2.5.3/Array.html#method-i-uniq-21 and https://ruby-doc.org/core-2.5.3/Array.html#method-i-uniq .
[17:54:33] leftylink: regardless of that, to answer the question "does it repeat", consider phrasing it as "have I seen it before?"
[17:54:46] sanscoeur: has joined #ruby
[17:54:47] baweaver: uniq doesn't modify the list.
[17:59:48] idiocrash: has joined #ruby
[18:00:37] ua: has joined #ruby
[18:01:16] laaron: has joined #ruby
[18:06:45] tiff: has joined #ruby
[18:11:59] catbusters: has joined #ruby
[18:15:11] tdy: has joined #ruby
[18:15:22] Swyper: does compact remove all nil and '' elements from an array aswell? The docs only show it removing nil, I think
[18:17:00] tiff: has joined #ruby
[18:19:26] Swyper: https://dpaste.de/BBqa
[18:19:41] Swyper: my failing test, has one nil at the front I can't seem to get rid of, not sure why
[18:22:20] baweaver: &>> 'aabbcccdef'.chars.group_by(&:itself).select { |ch, count| count == 1 }.keys
[18:22:21] rubydoc: # => [] (https://carc.in/#/r/5w00)
[18:22:50] baweaver: &>> 'aabbcccdef'.chars.group_by(&:itself).select { |ch, chs| chs.size == 1 }.keys
[18:22:51] rubydoc: # => ["d", "e", "f"] (https://carc.in/#/r/5w01)
[18:23:16] baweaver: &>> 'aabbcccdef'.chars.group_by(&:itself)
[18:23:16] rubydoc: # => {"a"=>["a", "a"], "b"=>["b", "b"], "c"=>["c", "c", "c"], "d"=>["d"], "e"=>["e"], "f"=>["f"]} (https://carc.in/#/r/5w02)
[18:24:02] baweaver: ACTION really wants a count_by function
[18:33:06] Swyper: repeated_char = string.each_char.select { |c| (string.count(c) > 1) && !(c.empty?)}
[18:33:31] Swyper: I'm just confused as to how select is still allowing "" as a repeating character
[18:33:47] Swyper: && !(c.empty?) should have taken care of that no?
[18:34:11] Swyper: though I see what you did with .size but I am still curious as to why what I am doing is incorrect
[18:35:44] Rapture: has joined #ruby
[18:38:30] leftylink: because " " isn't empty
[18:38:35] leftylink: &>> " ".empty?
[18:38:36] rubydoc: # => false (https://carc.in/#/r/5w0a)
[18:39:23] leftylink: only "" is empty.
[18:39:26] leftylink: &>> "".empty?
[18:39:26] rubydoc: # => true (https://carc.in/#/r/5w0b)
[18:41:55] kapil____: has joined #ruby
[18:42:31] Swyper: repeated_char = string.each_char.select { |c| (string.count(c) > 1) && !(c.empty?) && c != " "} works =D
[18:45:36] leftylink: it is helpful to remove code that does nothing, so that it does not confuse readers. the c.empty? part is doing nothing
[18:46:56] Swyper: &>> "xyz!".count(a..z)
[18:46:57] rubydoc: # => undefined local variable or method `a' for main:Object (NameError) (https://carc.in/#/r/5w0c)
[18:47:06] Swyper: &>> "xyz!".count("a..z")
[18:47:06] rubydoc: # => 1 (https://carc.in/#/r/5w0d)
[18:47:20] Swyper: anyway to use count with a range?
[18:47:27] Swyper: in this case I want all letters from a-z
[18:52:13] leftylink: as the docs will say, no... but see the docs for Enumerable#count with a block.
[18:56:59] Swyper: ary.count{ |x| x%2==0 } #=> 3, so I count string.count { |x| ("a..z").include?(x) } or something like this?
[19:00:39] yokel: has joined #ruby
[19:03:07] laaron: has joined #ruby
[19:05:04] Dbugger: has joined #ruby
[19:05:12] tiff: has joined #ruby
[19:11:59] cthulchu: has joined #ruby
[19:13:00] phaul: For strings the count can count a string range, but not a normal range. 'a-z' would count chars from a to z
[19:13:08] phaul: &ri String#count
[19:13:08] rubydoc: https://ruby-doc.org/core-2.6/String.html#method-i-count
[19:14:13] phaul: &>> "xyz!".count("a-z")
[19:14:13] rubydoc: # => 3 (https://carc.in/#/r/5w1a)
[19:14:54] leftylink: that is cool
[19:17:42] Swyper: &>> "xyzZZ!".count("a-z")
[19:17:43] rubydoc: # => 3 (https://carc.in/#/r/5w1m)
[19:18:09] Swyper: &>> "xyzZZ!".count("a-z" || "A-Z")
[19:18:10] rubydoc: # => 3 (https://carc.in/#/r/5w1o)
[19:18:22] Swyper: phaul: anyway to make it inclusive for uppercase character aswell?
[19:18:28] phaul: &>> "xyz!".count("a-zA-Z")
[19:18:29] rubydoc: # => 3 (https://carc.in/#/r/5w1p)
[19:18:42] phaul: &>> "xyz!".downcase.count("a-z")
[19:18:42] rubydoc: # => 3 (https://carc.in/#/r/5w1q)
[19:18:53] phaul: im an idiot
[19:19:11] phaul: &>> "xyzZZ!".count("a-zA-Z")
[19:19:11] rubydoc: # => 5 (https://carc.in/#/r/5w1s)
[19:19:17] phaul: that's what I meant
[19:19:18] leftylink: Swyper: it's improtant to note, there's nothing magical about the syntax "a-z" || "A-Z". the expression evaluates to "a-z".
[19:19:43] Swyper: leftylink: I'm just trying to figure out the logic with which it works
[19:19:50] leftylink: so the attempt of `"xyzZZ!".count("a-z" || "A-Z")` is exactly equal to `"xyzZZ!".count("a-z")`
[19:20:09] leftylink: to understand the logic of how it works, it is useful to understand that there is nothing magical going on with the syntax there
[19:20:27] leftylink: `"a-z" || "A-Z"` is evaluated just as it would be in any other context
[19:21:41] phaul: also worth noting that 'a-z' or 'a-zA-Z' are just strings and String#count implements some special behaviour for them if the argument matches a certain pattern
[19:25:39] Mike11: has joined #ruby
[19:31:08] KazeFX: has joined #ruby
[19:33:10] phaul: &>> %w(a A).map(&:ord)
[19:33:11] rubydoc: # => [97, 65] (https://carc.in/#/r/5w2e)
[19:35:17] phaul: so it would seem that string.count(A-z) would also work, but it would count chars in in between the lower alpha and upper alpha ranges
[19:35:36] hutch: has joined #ruby
[19:38:35] Iambchop: &>> (?Z..?a).to_a.join
[19:38:39] rubydoc: # => "Z[\\]^_`a" (https://carc.in/#/r/5w2n)
[19:42:41] tdy: has joined #ruby
[19:48:54] donofrio: has joined #ruby
[19:55:39] jottr: has joined #ruby
[19:57:05] Swyper: copy_of_string = string.map.with_index { |word, i| word.count("a-zA-Z") }
[19:57:19] Swyper: I need to get the two longest strings without accounting for anything thats not a letter
[19:57:37] Swyper: if I do .sort then I end up just the counts in numerical order
[19:57:53] Swyper: any ideas for how I can get the top 2 longest alphabetical strings?
[19:57:59] Swyper: using what i have now, ideally
[19:59:07] leftylink: &ri Enumerable#max_by
[19:59:07] rubydoc: https://ruby-doc.org/core-2.6/Enumerable.html#method-i-max_by
[19:59:14] leftylink: is my suggestion
[20:01:28] laaron-: has joined #ruby
[20:02:06] dinfuehr: has joined #ruby
[20:02:31] leftylink: or, if you insist on keeping the separate array of # of letters of each string, then you want Array#zip
[20:04:44] Swyper: https://www.rubyguides.com/2017/10/array-zip-method/
[20:05:12] Swyper: I suppose I need the words sorted in order by word.count("a-zA-Z")
[20:05:37] Swyper: this map would just give me a count of each element in the array with the parameters given in Count
[20:05:51] Swyper: but I need to output the original elements
[20:06:06] Swyper: the top 2 longest alphabetical elements
[20:06:12] leftylink: my suggestion stnads.
[20:06:21] leftylink: or I guess you can use Enumerable#sort_by if you want
[20:09:40] uplime: has joined #ruby
[20:15:50] Swyper: I'm finding this one to be *very* confusing
[20:16:25] Swyper: https://dpaste.de/2Avq
[20:16:31] Swyper: tests + current code
[20:18:45] phaul: Swyper: what are the two things passed to the block of sort_by?
[20:19:05] phaul: &ri Enumerable#sort_by
[20:19:05] rubydoc: https://ruby-doc.org/core-2.6/Enumerable.html#method-i-sort_by
[20:19:24] Swyper: sorry that should not be there
[20:19:50] Swyper: but the errors are still the same
[20:20:04] Swyper: copy_of_string = string.split.sort_by { |word| word.count("a-zA-Z") }
[20:20:05] Swyper: return copy_of_string[copy_of_string.length-1] + copy_of_string[copy_of_string.length-2]
[20:20:22] phaul: which part of the error confuses you? we can explain
[20:23:57] raulp: has joined #ruby
[20:24:05] phaul: first is really just coomplaining that 2 != 14. The test is not the best that's why it's outputting that small novel about oobjects not being the same. If you change it to expect(longest_two_words(string).length).to eq 2 it would output something more sane
[20:28:02] Swyper: ah phaul thanks I'll update the test and report back
[20:41:04] garyserj: has joined #ruby
[20:43:08] Swyper: https://dpaste.de/PvWP
[20:43:14] Swyper: gives me an error xD
[20:46:22] leftylink: you forgot to say what error.
[20:50:43] Swyper: undefined local variable or method `actual' for #<RSpec::ExampleGroups::EnumerablesPart2::LongestTwoWords:0x00007f804c99fec0>
[20:50:56] leftylink: then you should define it
[20:50:59] leftylink: if you expect the test to work
[20:51:09] venmx: has joined #ruby
[20:54:04] tiff: has joined #ruby
[20:54:40] tiff: has joined #ruby
[21:00:48] laaron: has joined #ruby
[21:04:49] SeepingN: has joined #ruby
[21:06:16] BTRE: has joined #ruby
[21:08:00] sandelius: has joined #ruby
[21:09:47] tiff: has joined #ruby
[21:16:30] phaul: they are gone ... they were trying to fix the eq, but followed the rspec recommendation which just used generic terms like expected , actual.
[21:20:48] connermcd: has joined #ruby
[21:31:16] hutch: has joined #ruby
[21:41:33] tiff: has joined #ruby
[21:41:34] nowhere_man: has joined #ruby
[21:51:17] m0w: has joined #ruby
[22:06:18] hutch: has joined #ruby
[22:07:35] ruby[bot]: has joined #ruby
[22:07:36] ChanServ: +o ruby[bot]
[22:08:07] ruby[bot]: -b+b *!*@c-76-28-115-114.hsd1.ct.comcast.net *!*@c-76-28-115-114.hsd1.ct.comcast.net$#ruby-banned
[22:12:40] cd: has joined #ruby
[22:20:22] kapil____: has joined #ruby
[22:20:29] MasterAsia: has joined #ruby
[22:21:13] Swyper: has joined #ruby
[22:22:04] Swyper: https://dpaste.de/2Avq
[22:22:19] Swyper: object identity in this example.
[22:22:31] Swyper: why are the objects not the same? is it because string is immutable ?
[22:22:40] leftylink: because 2 != 14
[22:22:49] phaul: Swyper: sorry I was away from keyboard I coulnt respond
[22:22:55] Swyper: no problem
[22:23:05] leftylink: or, well, 2.equal?(14) was false, to be more precise
[22:23:05] irdr: has joined #ruby
[22:23:09] leftylink: but I was imprecise and just said !=
[22:23:48] Swyper: so how do I fix the error can you give me some hints
[22:25:23] phaul: first of just insert the .to eq(2) instead of .to be(2) , don't replace the whole thing
[22:25:50] phaul: that should get rid of some of the confusing parts.
[22:26:10] phaul: Then you will have to figure out why your algorithm is returning 14 instead of 2
[22:27:07] phaul: the actual and expected are just generic terms in the rspec message, and if you take them literarly they are not defined
[22:27:24] baweaver: &>> [1,2,3,4,5].last(2)
[22:27:25] rubydoc: # => [4, 5] (https://carc.in/#/r/5w3k)
[22:27:40] baweaver: `return` isn't really needed in ruby either.
[22:28:44] baweaver: Also you're quite literally returning both of the strings as one string
[22:28:44] baweaver: instead of as an array, which is probably what you intended.
[22:30:03] baweaver: &>> 'some words are longer than other words, who would have thought?'.split.max_by(2) { |w| w.count('a-zA-Z') }
[22:30:04] rubydoc: # => ["thought?", "longer"] (https://carc.in/#/r/5w3l)
[22:30:44] baweaver: Interesting part is that that _includes_ punctuation
[22:30:44] baweaver: not in the count, but in the return.
[22:33:09] tdy: has joined #ruby
[22:34:16] Swyper: I made that so much harder then it needed to be
[22:34:46] baweaver: That phrase gets far more common the more programming one does.
[22:40:19] memofun: has joined #ruby
[22:46:42] hiroaki: has joined #ruby
[22:48:07] dviola: has joined #ruby
[22:54:16] davidw_: has joined #ruby
[22:55:03] orbyt_: has joined #ruby
[23:00:42] laaron-: has joined #ruby
[23:15:52] uplime: has joined #ruby
[23:18:50] hutch: has joined #ruby
[23:26:33] khanred: has joined #ruby
[23:30:53] rkazak: has joined #ruby
[23:32:35] khanred: has left #ruby: ("Leaving")
[23:32:56] umjisus: has joined #ruby
[23:50:59] nowhere_man: has joined #ruby
[23:52:37] MasterAsia: has joined #ruby
[23:57:54] SeepingN: has joined #ruby