« Back to channel list

#ruby - 10 August 2018

« Back 1 day Forward 1 day »
[00:00:05] baweaver: I'd said it two times above: str.chars.rotate ....
[00:00:15] baweaver: you missed that twice.
[00:00:19] this_dude: ok but idk how to write that out
[00:00:35] havenwood: 'this_dude'.chars.rotate
[00:00:40] this_dude: s.chars.rotate(leftShift).rotate(rightShift)
[00:00:53] havenwood: this_dude: We don't use headlessCamelCase ever in Ruby.
[00:00:55] baweaver: Remember rotate defaults to right
[00:01:06] baweaver: so you get two right rotates like that
[00:01:08] havenwood: this_dude: left_shift and right_shift in snake_case
[00:01:10] baweaver: but the syntax is correct.
[00:01:19] this_dude: so then it would be
[00:01:31] baweaver: one needs to be negative.
[00:01:38] this_dude: s.chars.rotate(rightShifts - leftShifts)
[00:02:02] baweaver: I'd just threw a negative on a second rotate
[00:02:03] this_dude: i got it super wrong then
[00:02:03] galaxie: Hmm, can I sort/prioritize RuboCop warnings? Like, choose which ones pop up first in, say, Vim Syntastic?
[00:02:07] baweaver: >> def get_shifted_string(str, right, left) str.chars.rotate(right).rotate(-left).join end; get_shifted_string('foobar', 3, 5)
[00:02:12] ruby[bot]: baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[00:02:13] mroutis: sure, galaxie
[00:02:20] galaxie: I believe Syntastic has some ability to do that, but I was wondering if RuboCop itself had the ability.
[00:02:23] mroutis: you can specify them in a .rubocop.yml
[00:02:53] mroutis: read the first paragraph, galaxie, https://rubocop.readthedocs.io/en/latest/configuration/
[00:03:46] galaxie: mroutis: Well, yes, I can disable cops, but if I really couldn't care less about line length compared to, say, security warnings..
[00:04:09] mroutis: oh, right, I misread that, sorry
[00:04:13] galaxie: mroutis: Oh wait, is it severity I'm looking for?
[00:04:33] mroutis: yep, galaxie
[00:04:44] chouhoulis: has joined #ruby
[00:04:47] ansraliant: has joined #ruby
[00:05:12] this_dude: i got the answer
[00:05:15] this_dude: way too late ofc
[00:05:26] this_dude: if we had that conversation earlier i wouldve passed..
[00:05:35] this_dude: s.chars.rotate(rightShifts).rotate(-leftShifts).join
[00:05:51] mroutis: and you can filter the severity when calling `rubocop`
[00:06:12] this_dude: I have one last try
[00:06:21] havenwood: this_dude: s.chars.rotate(right_shifts - left_shifts).join
[00:06:30] this_dude: that works too
[00:06:37] this_dude: i wish y'all wouldve told me that earlier
[00:06:43] this_dude: you were being kinda creul tbh..
[00:06:59] this_dude: like ok i get it..self study is the best way to learn
[00:07:01] havenwood: this_dude: Your timing is just off.
[00:07:04] mroutis: using something like `rubocop --fail-level falat`, galaxie
[00:07:41] havenwood: this_dude: You decided to learn *during* the test. We'd have been happy to help back when we could have.
[00:08:01] this_dude: because i have no idea what kinda problems theyre gonna throw at me
[00:08:12] this_dude: and .rotate and all that werent in the resources they provided me to study
[00:08:16] baweaver: codewars.com
[00:08:24] this_dude: i studied and memorized everything they provided me with
[00:08:45] this_dude: but its simply not enough..i feel the test is rigged to be for people who have coding experience and that makes me mad
[00:08:49] mroutis: this_dude, you can achieve the same thing without `.rotate`
[00:09:27] galaxie: mroutis: Minimum severity (A/R/C/W/E/F) for exit ... what's A stand for? R is Refactor..
[00:09:37] galaxie: mroutis: Allowed?!
[00:09:42] mroutis: A is autocorrect, I guess, galaxie
[00:09:58] cagomez: has joined #ruby
[00:10:17] this_dude: should i just jump into my last try and i fail just give up on being a coder ..
[00:10:26] this_dude: cause im limited on time
[00:10:35] this_dude: i only have 2 days left to take the last attempt
[00:10:40] this_dude: and idk what else i can possibly study
[00:10:45] mroutis: well, prepare
[00:10:47] baweaver: Go through a bunch of problems on codewars.com
[00:10:54] baweaver: spend a solid day on it.
[00:10:57] baweaver: or two even
[00:11:04] al2o3-cr: this_dude: possibly the language
[00:11:07] baweaver: that's what I tend to do to remember stupid little things.
[00:11:11] this_dude: okay let me see whats up
[00:11:54] blood: Is there no way to remove a parent element after matching a specific element by value using REXML?
[00:12:22] mroutis: blood, do you have an example?
[00:12:27] blood: yes one moment
[00:12:29] mroutis: this_dude, http://ruby-doc.org/gettingstarted/
[00:12:35] jcarl: has joined #ruby
[00:13:03] this_dude: im trying this coding wars thing
[00:13:07] this_dude: its kinda cool actually
[00:13:10] this_dude: really helpful so far
[00:13:21] al2o3-cr: this_dude: what katas?
[00:13:47] mroutis: lol, it've been 5 minutes, "really helpful so far"
[00:13:56] this_dude: dude ive gone through like 5 problems already
[00:13:58] this_dude: its super cool
[00:14:15] this_dude: and the thing is when im not on a time constraint i can think so much clearer
[00:14:27] this_dude: im terrible under timed pressure
[00:14:37] mroutis: life is time constrained, this_dude
[00:14:41] blood: mroutis: https://gist.github.com/bloodmc/ff198fbea2f099efb19adfde15db0b05
[00:14:44] cagomez_: has joined #ruby
[00:15:11] this_dude: why are you guys all so cryptic ahaha
[00:15:20] galaxie: mroutis: Is this supposed to do what I thought it was? It shouldn't exit unless there is at least one error: rubocop -P -E --fail-level E --format emacs FILE -c CONFIG_FILE
[00:15:22] havenwood: ?guys this_dude
[00:15:22] ruby[bot]: this_dude: Though inclusion was probably intended, not everyone relates to being "one of the guys". Maybe consider using "folks", "all", "y'all", or "everyone" instead?
[00:15:23] this_dude: i feel like y'all shouldve been philosophy majors
[00:15:31] havenwood: this_dude: I was a philosophy major.
[00:15:43] this_dude: i forgot havenwoods name is sarah
[00:15:48] blood: Currently with xml_fragment, it will call the remove_tag method which calls the REXML code as you see in gist. This only removes the element matched but will leave the parent empty
[00:15:50] this_dude: MAKES SENSE
[00:15:51] havenwood: this_dude: my name is shannon
[00:15:59] this_dude: yeah that...i apologize
[00:16:07] blood: I tried to review the ruby docs but couldn't find anything on how to remove a parent element
[00:17:30] galaxie: mroutis: Also, it's still sorting by line number, not severity
[00:18:05] this_dude: ooo heres something idk
[00:18:12] this_dude: how do you return a sum in ruby in terms of binary
[00:18:29] mroutis: galaxie, can't tell, sorry :/
[00:18:30] al2o3-cr: this_dude: how'd you mean?
[00:19:03] galaxie: mroutis: Any experience with Syntastic/Vim?
[00:19:08] goez: has joined #ruby
[00:19:27] this_dude: i want to add two integers and return their sum in binary
[00:19:31] this_dude: for example
[00:19:33] mroutis: no, galaxie, I use vim but not syntastic
[00:19:39] this_dude: sum = a + b
[00:19:46] this_dude: i want sum in binary
[00:19:58] mroutis: you could try debugging by running rubocop outside of vim, without syntastic
[00:20:05] al2o3-cr: >> 255.to_s(2)
[00:20:06] ruby[bot]: al2o3-cr: # => "11111111" (https://eval.in/1046164)
[00:20:16] havenwood: this_dude: my little code dojo in Topanga was the original code wars dojo ;-)
[00:20:19] galaxie: mroutis: What do you use, then?
[00:20:34] this_dude: whats that do
[00:20:51] this_dude: isnt .to_s converstion of an array to a string
[00:20:58] this_dude: conversion*
[00:21:11] havenwood: this_dude: It's explicit conversion from anything to a String.
[00:21:16] havenwood: this_dude: (Not Array.)
[00:21:30] havenwood: [].to_s #=> "[]"
[00:21:32] this_dude: how does that return binary
[00:21:42] mroutis: when I'm about to open a PR, I run rubocop to tests for style issues, galaxie
[00:21:58] blood: mroutis: if you need more information let me know =) Thanks!
[00:22:06] this_dude: is the 2 a definition of the string in terms of base 2?
[00:22:18] Creatornator: has joined #ruby
[00:23:10] al2o3-cr: this_dude: representation
[00:23:13] mroutis: yep, blood, sorry, actually, I didn't understood what you were trying to achieve; you have two operations, right? extracting the content from the XML and modifying the XML, right?
[00:23:22] havenwood: this_dude: 42.method(:to_s).owner #=> Integer
[00:23:41] al2o3-cr: >> 255.to_s(16) # hex
[00:23:42] ruby[bot]: al2o3-cr: # => "ff" (https://eval.in/1046165)
[00:23:45] blood: Basically, I need to modify/remove/add XML
[00:23:48] havenwood: "Returns a string containing the representation of int radix base (between 2 and 36)."
[00:23:55] blood: I have no issues with modify/add , only remove
[00:24:05] this_dude: >> 2.to_s(2)
[00:24:06] ruby[bot]: this_dude: # => "10" (https://eval.in/1046166)
[00:24:13] havenwood: this_dude: Yeah, binary.
[00:24:13] this_dude: THATS SO COOL
[00:24:23] blood: So when using REXML, it will remove the matched element from xml properly but it doesn't handle the parent (assuming the parent isn't root)
[00:24:41] havenwood: this_dude: "10".to_i(2) #=> 2
[00:25:07] blood: I'm trying to match an element based on a value and have it remove all elements including children up to root
[00:25:16] havenwood: this_dude: Or strict conversion: Integer("10", 2) #=> 2
[00:25:58] this_dude: so i can take an integer string value and turn it into an integer in terms of other bases
[00:26:03] this_dude: so i can go back and forth
[00:26:05] this_dude: thats SO COOL
[00:26:28] mroutis: mhm, blood, why don't you find the parent before deleting the element and call `delete_all(parent_path)`
[00:26:58] mroutis: I'm just trying to figure out what's going on, sorry if I can't help that much
[00:27:05] this_dude: how do i go to the next question on this thing havenwood
[00:27:31] blood: Because I only want to delete an element if a child element contains a value I specify. So when a child element is matched, I want to delete it as well as any parents it has up to root
[00:27:43] blood: If I can do that then sure let me know =)
[00:27:49] havenwood: this_dude: I don't know the question. Are you allowed direct assistance?
[00:28:21] blood: I assume I should just check children on each element as I traverse then delete if it contains my criteria
[00:29:03] mroutis: I think that could work, blood ^
[00:29:07] this_dude: i meant after i finish one correctly
[00:29:11] this_dude: theres no next button haha
[00:29:13] al2o3-cr: this_dude: quick little test for you, you up for it?
[00:29:34] blood: If this were java, i would be done already but just starting to work with ruby =)
[00:30:02] al2o3-cr: this_dude: convert "#ff0000" into rgb constituent parts
[00:30:39] this_dude: rgb constituent parts
[00:30:50] mroutis: I've never used REXML, always Nokogiri <3
[00:30:56] al2o3-cr: this_dude: so return an array with 3 integers
[00:31:01] this_dude: isnt #ff0000 a color code lol
[00:31:08] al2o3-cr: this_dude: yep
[00:31:17] this_dude: anyways ok i got this
[00:31:20] this_dude: gimme a sec
[00:31:27] blood: mroutis: better? I'm only using REXML since it was used for this puppet module
[00:31:35] al2o3-cr: this_dude: ok
[00:31:38] this_dude: can i assume thats in hexidecimal since its a color code
[00:31:50] mroutis: can't compare, since I haven't use REXML :p
[00:32:33] this_dude: >> "ff0000".to_i(16).to_a
[00:32:34] ruby[bot]: this_dude: # => undefined method `to_a' for 16711680:Fixnum ...check link for more (https://eval.in/1046167)
[00:32:44] thejs: has joined #ruby
[00:32:54] blood: http://www.rubyinside.com/ruby-xml-performance-benchmarks-1641.html According to this, REXML is painfully slow
[00:33:03] blood: i should give nokogiri a shot
[00:33:24] this_dude: "ff0000".to_i(16).split.to_a
[00:33:30] this_dude: >> "ff0000".to_i(16).split.to_a
[00:33:31] ruby[bot]: this_dude: # => undefined method `split' for 16711680:Fixnum (NoMethodError) ...check link for more (https://eval.in/1046168)
[00:33:45] havenwood: this_dude: try in your own irb first
[00:34:06] this_dude: when using irb in command line
[00:34:10] postmodern: has joined #ruby
[00:34:15] this_dude: if i wanna use it for ruby do i execute ruby irb
[00:34:18] this_dude: or still just irb
[00:34:36] havenwood: this_dude: from the command line, just: irb
[00:35:38] this_dude: you said you want a result of an array with 2 numbers
[00:35:44] havenwood: this_dude: 3
[00:35:56] this_dude: but thats translates to 16711680
[00:35:59] this_dude: yeah 3 srry
[00:36:06] this_dude: so i dont understand what you want exactly
[00:36:14] havenwood: this_dude: [255, 0, 0]
[00:36:31] al2o3-cr: this_dude: for a clue use String#scan(rexexp) Enumerable#map String#hex
[00:36:56] havenwood: this_dude: What's base ten number does "FF" represent in hex?
[00:37:14] havenwood: >> "FF".hex
[00:37:15] ruby[bot]: havenwood: # => 255 (https://eval.in/1046169)
[00:37:44] havenwood: this_dude: What's "A" in hex?
[00:37:45] ruby[bot]: this_dude: # => 256 (https://eval.in/1046170)
[00:38:02] havenwood: this_dude: right
[00:38:15] havenwood: this_dude: And "AA" is?
[00:38:44] havenwood: this_dude: (Try in IRB.)
[00:39:09] this_dude: >> "AA".hex
[00:39:10] ruby[bot]: this_dude: # => 170 (https://eval.in/1046171)
[00:39:55] havenwood: this_dude: 1, 2, 3, ..., 9, 10, A, B, ... E, F, then ???? what's next?
[00:40:26] galaxie: mroutis: How's this? rubocop -P -E --format emacs FILE -c CONFIG_FILE | ruby -e'c=Proc.new{|s|["A","R","C","W","E","F"].index(s.split(":")[-3][1])};puts ARGF.read.split("\n").sort{|a,b|c.call(b)<=>c.call(a)}.join("\n")'
[00:40:34] havenwood: this_dude: 10
[00:40:43] havenwood: this_dude: like what's after 9 in base 10?
[00:40:53] havenwood: this_dude: nope, 10
[00:41:03] havenwood: 8, 9, and ... 10!
[00:41:08] mroutis: has left #ruby: ()
[00:41:17] this_dude: but base 10 is 0-9
[00:41:32] havenwood: this_dude: right, and in base 10 (normal counting), what's after 9?
[00:42:00] this_dude: how does 10 come after F
[00:42:35] havenwood: this_dude: in normal counting, you exhaust the set, then put a 1 in front, right? same rule.
[00:42:45] havenwood: this_dude: E, F, 10, 11
[00:42:54] this_dude: <havenwood> this_dude: 1, 2, 3, ..., 9, 10, A, B, ... E, F, then ???? what's next?
[00:43:00] havenwood: this_dude: 10
[00:43:04] this_dude: why did you put a 10 after 9 then
[00:43:08] havenwood: this_dude: i fail
[00:43:22] havenwood: multitasking on a base 10 brain
[00:43:33] this_dude: oh...so its ...9,a,b,c..etc
[00:43:40] havenwood: this_dude: yeah, sorry for the confusion
[00:43:57] havenwood: this_dude: like binary is: 0, 1, 10
[00:44:04] this_dude: ok makes sense
[00:44:10] this_dude: so for example
[00:44:35] havenwood: this_dude: So RGB is three numbers from 0-255.
[00:44:36] havenwood: this_dude: Or in hex, three numbers from "00" to "FF"
[00:44:58] havenwood: this_dude: in al2o3-cr's example, "FF", "00" and "00"
[00:45:04] havenwood: this_dude: which is 255, 0 and 0
[00:45:33] this_dude: they arent all one number?
[00:45:43] this_dude: how can you tell?
[00:45:52] havenwood: that's how RGB works
[00:46:00] this_dude: didnt know that
[00:46:12] this_dude: what does RGB stand for
[00:46:37] this_dude: red green blue
[00:46:42] havenwood: this_dude: or rather, the hex #RRGGBB representation is common in RGB
[00:47:35] havenwood: this_dude: So 100% red and 0% green and blue.
[00:47:47] this_dude: for FF0000?
[00:47:51] havenwood: this_dude: yes
[00:48:03] this_dude: that makes sense
[00:48:15] al2o3-cr: this_dude: i bet you don't remember crt televisions
[00:48:16] this_dude: let me do this problem on code wars hold on
[00:48:25] this_dude: remember what lmaoooo
[00:48:28] this_dude: dude im 21 XD
[00:49:04] al2o3-cr: embrace on the test given
[00:49:14] havenwood: this_dude: but how old is that in hex?
[00:50:03] this_dude: >> 21.to_s(16)
[00:50:04] ruby[bot]: this_dude: # => "15" (https://eval.in/1046172)
[00:50:30] this_dude: so question
[00:50:44] this_dude: can you execute an if statement outside of a while loop?
[00:51:30] havenwood: >> 'so what' if 'you can?'
[00:51:31] ruby[bot]: havenwood: # => /tmp/execpad-8a9b5ab462ab/source-8a9b5ab462ab:2: warning: string literal in condition ...check link for more (https://eval.in/1046173)
[00:51:53] havenwood: #=> "so what"
[00:52:34] havenwood: this_dude: Try in irb. Or you might want to just switch to pry right away.
[00:52:35] havenwood: this_dude: gem install pry pry-doc && pry
[00:52:38] al2o3-cr: havenwood: only on string literals not array, hash or any other objects.
[00:53:11] this_dude: for example can i just put if "statement" = "boundary" return true
[00:53:30] this_dude: better example
[00:53:32] this_dude: if x % (x.sqrt) == 0 return true
[00:53:42] this_dude: can i put that
[00:53:52] this_dude: or do i have to specify while x > 0
[00:54:04] havenwood: this_dude: return true if x % x.sqrt == 0
[00:54:16] havenwood: this_dude: but you'd not need the if, since it's already truthy
[00:54:37] al2o3-cr: yeah just; x % (x.sqrt) == 0
[00:54:57] this_dude: so just x % (x.sqrt) == 0; return true
[00:55:12] havenwood: this_dude: oh, for the early return you mean?
[00:55:13] MuffinPimp: has joined #ruby
[00:55:36] this_dude: while x > 0; if x % (x.sqrt) == 0; return true; elsif x % (x.sqrt) != 0; return false
[00:55:46] this_dude: is this written correctly?^
[00:56:14] this_dude: or is there a simpler way to write that
[00:56:36] al2o3-cr: no just; x % (x.sqrt) == 0 # it's either true or false.
[00:57:43] this_dude: x % (x.sqrt) == 0; return true; else return false
[00:57:45] patr0clus: has joined #ruby
[00:58:08] al2o3-cr: >> 5 % 4 == 0
[00:58:09] ruby[bot]: al2o3-cr: # => false (https://eval.in/1046174)
[00:58:16] al2o3-cr: >> 5 % 5 == 0
[00:58:17] ruby[bot]: al2o3-cr: # => true (https://eval.in/1046175)
[00:58:27] this_dude: ohhhh youre saying i dont have to put the "return false/true"
[00:58:33] this_dude: cause itll do it automatically
[00:58:46] al2o3-cr: yeah, dude.
[00:59:21] this_dude: its saying its wrong
[00:59:30] havenwood: this_dude: I'd write that as either:
[00:59:31] havenwood: 42.modulo(Math.sqrt(42)).zero?
[00:59:36] havenwood: 42 % 42 ** 0.5 == 0
[00:59:37] this_dude: the problem is to create a method that tells if a number inputted is a perfect square
[01:00:06] havenwood: assuming x is 42
[01:00:15] al2o3-cr: this_dude: well a perfect sqr is 1*1, 2*2, 3*3 and so forth
[01:00:16] this_dude: so then i could do
[01:01:09] this_dude: confused how to write thi
[01:01:52] al2o3-cr: this_dude: you're consusing square root with a squared number. use abs2
[01:02:23] this_dude: i guess my mathematical logic for is was that
[01:02:34] havenwood: this_dude: squaring
[01:02:35] havenwood: this_dude: I work at Square so we deal with this all the time!
[01:02:48] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[01:02:59] this_dude: if i take the square root of a number and divide it by the original number with modulo if its a perfect square itll return 0 no?
[01:03:29] al2o3-cr: this_dude: gist the test code again
[01:03:42] this_dude: hold on i gotta relocate coffee shop is closed
[01:03:57] this_dude: imma drive home be back in 15/20
[01:11:56] this_dude: has joined #ruby
[01:12:22] this_dude: i just found on outlet at the park
[01:12:31] this_dude: and connected to my phone hotspot
[01:13:16] this_dude: the mathematical way of figuring out if a number is a perfect square would be to take the square root of the number
[01:13:39] this_dude: and if the number can be divided by the square root with % and return 0 its true
[01:14:02] this_dude: >> 9 % (9.sqrt) == 0
[01:14:08] ruby[bot]: this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[01:14:22] this_dude: >> 9 % (9.sqrt) == 0?
[01:14:27] ruby[bot]: this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[01:15:01] havenwood: this_dude: 9.modulo(Math.sqrt(9)).zero? #=> true
[01:15:16] havenwood: this_dude: 9 % 9 ** 0.5 == 0 #=> true
[01:15:24] havenwood: this_dude: That's true.
[01:16:39] this_dude: whats ** 0.5
[01:16:44] this_dude: i dont understand that function
[01:17:19] al2o3-cr: this_dude: this_dude square root
[01:17:43] al2o3-cr: like n ** (1/3.0) is cube root
[01:18:19] al2o3-cr: this_dude: yep
[01:18:19] this_dude: 9 ** .05 == 9 ^ .5
[01:18:28] this_dude: makes sense okok
[01:18:58] al2o3-cr: ^ in ruby is exclusive OR
[01:20:01] al2o3-cr: this_dude: anyway where's the gist
[01:20:05] this_dude: hmm im doing something wrong
[01:20:15] al2o3-cr: this_dude: test code
[01:20:21] this_dude: oh for the problem im solving?
[01:21:17] this_dude: https://dpaste.de/HOmz
[01:21:46] this_dude: am i expressing x greater than or equal to 0 wrong?
[01:21:52] this_dude: is it => or >=
[01:22:05] al2o3-cr: this_dude: why you using a loop for that?
[01:22:49] al2o3-cr: this_dude: logic starts in the brain you know
[01:22:53] this_dude: should i just use
[01:23:01] this_dude: instead of while
[01:23:14] def_jam: has joined #ruby
[01:23:38] eb0t_: has joined #ruby
[01:23:52] this_dude: hmm its giving me a wrong response for the number 0
[01:24:00] this_dude: how do i overcome the fact that you cant divide by 0
[01:24:03] Radar: hello again friends.
[01:24:24] Radar: this_dude: please stop using while loops for things that do not need them.
[01:24:27] this_dude: do i just specify that if x == 0 return true
[01:24:32] goez: has joined #ruby
[01:24:34] Radar: whoever is encouraging you to write Ruby should go... away.
[01:24:43] Radar: well, write Ruby _like this_
[01:24:49] havenwood: >> 0.step.lazy.select { |n| Math.sqrt(n).modulo(1).zero? }.first 10
[01:24:50] ruby[bot]: havenwood: # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] (https://eval.in/1046180)
[01:25:16] Radar: Thank you havenwood for showing some neater Ruby code.
[01:25:41] this_dude: oh i fixed it
[01:25:42] this_dude: https://dpaste.de/v1F8
[01:26:19] this_dude: its cause the code im using is the code i need to use on the exam
[01:26:22] this_dude: i have one try left
[01:26:29] this_dude: i failed again while you were gone
[01:26:44] Radar: Gone / asleep same thing.
[01:26:59] Radar: Hmmm almost as if you shouldn't be writing Ruby so strangely? 🤔
[01:27:16] this_dude: its what they want idk
[01:27:23] Radar: Are you _certain_?
[01:27:23] this_dude: dont tell me tell them ahaha
[01:27:30] Radar: Where did they say this?
[01:27:45] this_dude: im gonna paste a SS ok?
[01:27:48] this_dude: its not of code
[01:28:16] this_dude: http://prntscr.com/kgusq6
[01:28:47] this_dude: thats where they specified
[01:28:53] this_dude: i was given a list of material to study
[01:28:56] Radar: Oh that again. I remember that.
[01:29:01] this_dude: its supposed to be "all i need to pass the exam"
[01:29:11] Radar: So the two times you failed the exam, did they tell you what you did wrong?
[01:29:23] this_dude: doesnt even say which ones i got wrong
[01:29:32] this_dude: "you failed you have x amount of tries left"
[01:29:34] Radar: Did you test your code and see if it actually returned what it expected?
[01:29:37] this_dude: and i get a new link to retry lol
[01:29:42] this_dude: i ran out of tiem
[01:29:46] this_dude: i got one of them
[01:29:48] Radar: So practice now.
[01:29:53] this_dude: the last 2 i got absolutely stuck on
[01:30:06] Radar: It is not that hard to write tests for code. I will bring up an example.
[01:30:07] this_dude: thats what im doing ...someone gave me a link to codewars.com
[01:30:09] this_dude: its helpful
[01:30:21] this_dude: im gonna spend the next day or so on there
[01:30:25] this_dude: and then go back to the exam
[01:31:47] Radar: https://gist.github.com/radar/b2bf7136341d7453c9f49cc3a6ddd081
[01:31:49] Radar: this_dude: ^
[01:32:15] Radar: It is a good idea to write automated tests like this to test your code. You will know the input and expected outputs and you can write tests to assert that your code does exactly what it should before you submit it.
[01:32:30] Radar: These tests then allow you to refactor your code after you've finished making them all pass.
[01:34:21] this_dude: thats a little confusing...i just write the code into notepad and execute it in my command line and see if it gives the expected result after putting in a number
[01:34:32] this_dude: or array or whatever its asking for
[01:37:07] baweaver: >> {}.respond_to?(:to_proc)
[01:37:08] ruby[bot]: baweaver: # => true (https://eval.in/1046181)
[01:37:17] baweaver: Radar / al2o3-cr: Oh yes
[01:38:08] al2o3-cr: this_dude: it's as simple as n ** 0.5 % 1 == 0
[01:39:02] this_dude: oh shoot you right
[01:39:08] al2o3-cr: as what havenwood and Radar wrote
[01:39:09] this_dude: my way worked but yours is way shorter
[01:39:25] this_dude: this is why i idolize y'all
[01:39:35] this_dude: so you realize how much ive learned from this irc chat?
[01:39:36] al2o3-cr: this_dude: you were told this by havenwood
[01:39:45] this_dude: i didnt see it srry
[01:39:50] baweaver: >> Point = Struct.new(:x, :y); origin = Point.new(0, 0); def destructure(target, &fn) fn.call *fn.parameters.map(&:last).map(&target.to_h) end; destructure(origin) { |x, y| x + y }
[01:39:51] ruby[bot]: baweaver: # => 0 (https://eval.in/1046182)
[01:40:01] this_dude: no but i mean the %1
[01:40:04] this_dude: instead of %n
[01:40:09] this_dude: i didnt think of that
[01:40:31] baweaver: Hash#to_proc => -> key { hash[key] }
[01:40:31] this_dude: cause if the square root returns a decimal its automtically not a perfect square
[01:40:38] this_dude: i didnt think to use %1
[01:40:39] herbmillerjr: has joined #ruby
[01:40:49] al2o3-cr: ok, why use % 1
[01:40:55] baweaver: Much faster than public send
[01:41:16] this_dude: because with %1 if n is 0 then i obviously cant divide by 0
[01:41:24] this_dude: so %1 makes me able to compute 0 as well
[01:41:40] this_dude: and eliminates the extra line of code i added for the 0 case
[01:41:44] al2o3-cr: wow, you are learning fast.
[01:42:05] this_dude: im a fast learner when im given answers and not told to research it myself ahahaha
[01:42:17] this_dude: i absorb information way faster that way
[01:42:57] this_dude: I have a photographic memory so if you just throw a bunch of info at me ill memorizze it
[01:42:58] al2o3-cr: it ensures it an integer.
[01:43:13] this_dude: instead of a float
[01:43:32] this_dude: anyways on to the next problem
[01:43:37] this_dude: this ones kinda weird but i got it
[01:43:38] al2o3-cr: cool, you're heading in the right direction now
[01:44:40] this_dude: new question
[01:44:56] this_dude: if i need to split a string
[01:45:24] this_dude: but i need to split it in two ways...can i do this --> .split("WUB","WUBWUB").join(" ")
[01:45:54] this_dude: so that it will remove any instance of both of those combinations of characters and replace it with " "
[01:46:14] al2o3-cr: try it and see.
[01:46:22] this_dude: i did and got an error
[01:46:23] this_dude: but idk why
[01:46:27] this_dude: doesnt specify
[01:46:37] al2o3-cr: show your code.
[01:47:48] this_dude: https://dpaste.de/wkYU
[01:48:34] al2o3-cr: this_dude: what is song and what is expected result?
[01:48:46] this_dude: oh i forgot someting
[01:48:53] this_dude: so the string inputed will be as such
[01:49:03] baweaver: >> ObjectSpace.each_object.select { |o| o.is_a?(Class) && o.instance_methods.include?(:to_proc) rescue false }
[01:49:03] ruby[bot]: baweaver: # => [Method, Proc, Hash, Symbol] (https://eval.in/1046185)
[01:49:38] this_dude: http://prntscr.com/kguxv2
[01:50:18] this_dude: so like the string can be "WUBIWUBHATEWUBWUBMYSELFWUB"
[01:50:19] al2o3-cr: this_dude: i said paste not image.
[01:50:27] this_dude: thats the problem
[01:50:30] this_dude: its super long
[01:50:44] this_dude: so like the string can be "WUBIWUBHATEWUBWUBMYSELFWUB"
[01:50:52] this_dude: and the result needs to be "I HATE MYSELF"
[01:51:12] al2o3-cr: is that the real result?
[01:51:44] this_dude: its the result my code should return
[01:52:53] al2o3-cr: by why insert that?
[01:53:15] this_dude: oh idk it was just a random string off the top of my head ahahaha
[01:53:49] this_dude: so, so far my code works only when theres no "WUB" at the beginning or end of the string
[01:53:56] this_dude: and when there's no "WUBWUB" in the string
[01:54:22] this_dude: i need to be able to specify that if the string starts or ends with "WUB" or "WUBWUB" then just delete it
[01:54:36] this_dude: and i need to be able to replace "WUBWUB" with " " the same way i did with just "WUB"
[01:54:49] shakes: has joined #ruby
[01:55:36] this_dude: can you specify multiple split parameters?
[01:55:45] this_dude: such as .split("WUB","WUBWUB")
[01:56:22] this_dude: or would it be .split("WUB").split("WUBWUB")
[01:56:27] this_dude: let me test it
[01:56:40] al2o3-cr: >> "WUBIWUBHATEWUBWUBMYSELFWUB".gsub(/WUB*/, ' ')
[01:56:41] ruby[bot]: al2o3-cr: # => " I HATE MYSELF " (https://eval.in/1046198)
[01:57:00] this_dude: oh but thats wrong
[01:57:09] this_dude: cause its returning a double space where theres a WUBWUB
[01:57:15] this_dude: thats one of the errors i got too
[01:57:49] this_dude: and its also returning a space at the beginning and end of the string
[01:57:58] this_dude: i need that to return "I HATE MYSELF"
[01:58:22] this_dude: thats where i'm stuck atm
[02:01:18] this_dude: wait i think i got it
[02:04:26] this_dude: https://dpaste.de/Hini
[02:05:56] al2o3-cr: this_dude: is it a constraint to use while loops?
[02:07:11] this_dude: i just figured i needed it
[02:07:21] this_dude: to test each index of string.split
[02:08:28] this_dude: https://dpaste.de/DmcO
[02:09:07] this_dude: this is where im at now...trying to take into account the other constraints about there not being allowed a space at the beginning or end of the strign result
[02:09:18] this_dude: and that you can have a double space in the string result either
[02:10:20] this_dude: and that you CANT have a double space in the string result either**
[02:11:39] tdy: has joined #ruby
[02:13:00] this_dude: oh wait i found an easier way to take care of the double space thing
[02:13:12] this_dude: res = res.split(" ").join(" ")
[02:13:25] this_dude: is this a valid command ahaha
[02:15:10] this_dude: shoot no that didnt work
[02:16:58] this_dude: did everyone go afk :/
[02:17:29] Radar: this_dude: So let's talk about https://gist.github.com/radar/b2bf7136341d7453c9f49cc3a6ddd081
[02:17:37] Radar: this_dude: This is using a test framework called minitest
[02:17:50] Radar: There are 3 tests here, that test the `is_square` function with the numbers 1, 4, and 5.
[02:18:11] Radar: This is saying for 1 + 4, the `is_square` method should return `true` (assert). But for 5, it should return false (refute)
[02:18:53] Radar: You can run this test file by saving it to a file and running `ruby thatfile.rb`
[02:19:27] Radar: This will show you 3 green dots and "3 runs, 3 assertions, 0 failures", which means that it ran 3 tests, and asserted (or refuted) 3 times, and there were 0 failures.
[02:19:32] this_dude: but thats for a problem i already finished
[02:19:41] Radar: Ok, so adapt it to the next problem then.
[02:19:57] this_dude: oh codewars is doing the same thing for me
[02:20:18] this_dude: http://www.codewars.com/kata/551dc350bf4e526099000ae5/train/ruby
[02:20:28] this_dude: it has those minitests in it too
[02:20:35] this_dude: and tells me where my result went wrong
[02:20:40] this_dude: my issue is idk how to fix it
[02:22:59] this_dude: okay fine simple question
[02:23:08] this_dude: how can i use .split to split two different parameters
[02:24:24] Radar: this_dude: input + expected output plz
[02:25:23] pabs: this_dude: if you mean split on two different parameters, you can do it like this:
[02:25:24] pabs: >> 'foo,bar:baz'.split(/,|:/)
[02:25:25] pabs: => ["foo", "bar", "baz"]
[02:25:26] ruby[bot]: pabs: # => ["foo", "bar", "baz"] (https://eval.in/1046209)
[02:26:22] al2o3-cr: this_dude: use gsub
[02:26:32] Radar: can we not give answers to a problem we haven't seen yet?
[02:27:01] this_dude: but i showed the problem
[02:27:11] Radar: [12:24:24] <Radar> this_dude: input + expected output plz
[02:27:18] Radar: I don't see a single message from you about that.
[02:27:23] al2o3-cr: Radar: i've seen it
[02:27:25] Radar: enter is not a space bar.
[02:27:26] this_dude: can i ss the problem?
[02:29:40] blood: https://dpaste.de/YnGt So I'm currently traversing nodes to find a specific match and delete the parent node if found. The issue is, I'm trying to traverse children within children until a match is found or there is no more children. I can't seem to find out how to do this with REXML. Any ideas?
[02:29:44] this_dude: ok heres a ss of the problem and expected input and output
[02:29:47] this_dude: http://prntscr.com/kgv7ho
[02:33:19] this_dude: oh okay i know what my issue is now
[02:33:48] this_dude: i need to be able to scan the string to see exactly how many "WUB"s there are and no matter how many it is only replace it with a single " "
[02:34:15] this_dude: its raining and im outside gotta relocate brb
[02:34:43] fluxAeon: has joined #ruby
[02:36:43] Radar: this_dude: Ok, can you work out how to replace all the WUBs with a single space?
[02:37:19] Radar: this_dude: So if I had "AWUBWUBB" That would give me "A<space><space>B"
[02:40:56] mroutis: has joined #ruby
[02:49:42] lupine: has joined #ruby
[02:55:22] thejs: has joined #ruby
[02:58:02] maryo_: has joined #ruby
[02:59:39] JamJam_kid: has joined #ruby
[03:00:31] cadillac_: has joined #ruby
[03:08:16] blood: Is there a better way to handle this https://dpaste.de/Y1J2 ? This runs pretty slow
[03:08:25] blood: But it does work...
[03:10:14] blood: mroutis: I got a method to work but REXML runs extremely slow
[03:10:59] blood: I'll need to convert what I have to nokogiri
[03:12:53] this_dude: has joined #ruby
[03:13:22] braincrash: has joined #ruby
[03:14:09] al2o3-cr: this_dude: wb
[03:14:11] mojtaba: has joined #ruby
[03:14:26] this_dude: so back to what i was asking before
[03:14:49] this_dude: this command line --> res = song.split("WUB"||"WUBWUB").join(" ")
[03:14:57] this_dude: is obviously incorrectly written
[03:15:17] this_dude: but i need to be able to remove "WUB" no matter how many times its repeated
[03:15:25] this_dude: i.e. "WUBWUBWUB" or "WUBWUBWUBWUB"
[03:15:33] this_dude: and still replace it with just a single space
[03:15:36] ArahaelPi: this_dude: That reminds me of the story: "Beyond lies the Wub".
[03:16:31] blood: What version of nokogiri supports ruby 2.1.9?
[03:17:24] this_dude: any idea how to do that?
[03:17:49] al2o3-cr: this_dude: i have an idea
[03:18:11] this_dude: inb4 its a sarcastic idea :/
[03:18:23] Radar: [12:36:43] <Radar> this_dude: Ok, can you work out how to replace all the WUBs with a single space?
[03:18:26] Radar: [12:37:19] <Radar> this_dude: So if I had "AWUBWUBB" That would give me "A<space><space>B"
[03:18:47] this_dude: oh i went afk for that..let me load the log hold on
[03:19:15] this_dude: oh so for that one
[03:19:31] this_dude: i could just use song.split("WUBWUB").join(" ")
[03:20:33] this_dude: but in the case of one of the minitests on the site it has "WUBWUBWUB"..its super inefficient to write the same line of code for every increased instance of the use of the word "WUB
[03:21:00] this_dude: and the problem states that it can be any random number of times that "WUB" is used
[03:21:54] this_dude: or for [12:37:19] <Radar> this_dude: So if I had "AWUBWUBB" That would give me "A<space><space>B"
[03:22:29] this_dude: it would be song.split("WUB").join(" ") to give "A<space><space>B"
[03:23:07] Radar: >> AWUBWUBBsplit("WUB").join(" ")
[03:23:09] ruby[bot]: Radar: # => undefined method `AWUBWUBBsplit' for main:Object (NoMethodError) ...check link for more (https://eval.in/1046224)
[03:23:15] Radar: >> "AWUBWUBB".split("WUB").join(" ")
[03:23:16] ruby[bot]: Radar: # => "A B" (https://eval.in/1046225)
[03:23:20] Radar: this_dude: right.
[03:23:52] this_dude: so now i need it to only return a single space instead
[03:23:59] orbyt_: has joined #ruby
[03:24:01] this_dude: even if its WUB x3,4,5,etc
[03:24:19] Radar: this_dude: Then there's probably a method you don't know yet: squeeze. That'll remove the spaces. You should probably read the docs around that method before using it.
[03:24:44] this_dude: oh that is new info ty
[03:24:54] this_dude: have any links?
[03:26:48] this_dude: yeah im googling it rn ahahah
[03:26:56] this_dude: https://apidock.com/ruby/String/squeeze
[03:30:53] this_dude: wow thats so easy
[03:31:27] this_dude: can i do .squeeze(" ")
[03:31:33] this_dude: to specify what to squeeze?
[03:33:20] this_dude: gonna test it..sorry stupid question
[03:34:31] Radar: he is learning
[03:34:38] Radar: bbl lunch
[03:35:03] this_dude: got it! just once last thing to figure out
[03:35:13] this_dude: i cant have spaces at the beginning or end of the result string
[03:39:27] this_dude: ok absolutely no idea how to do that
[03:42:04] lupine: has joined #ruby
[03:42:05] Caerus: as with a lot of things in ruby. very simple ;) it is one of the string methods.
[03:44:03] Caerus: >> " foo bar ".strip
[03:44:04] ruby[bot]: Caerus: # => "foo bar" (https://eval.in/1046228)
[03:44:25] this_dude: ruby never fails to make me feel stupid
[03:45:01] this_dude: i was gonna do this
[03:45:16] this_dude: if res.split[0] == ' '; res.split[0].shift; elsif res.split[res.length] == ' '; res.split[res.length].pop
[03:47:58] Caerus: I am far for being an expert at ruby, but one thing that was very clear early on, whenever you find yourself looking at very complicated code, take a step back and shift through the methods of the class you´re working with.
[03:48:33] this_dude: is there like...a list of methods lol
[03:48:33] Caerus: chances are, there´s a more idiomatic way
[03:48:44] this_dude: cause i had no idea those were a thing
[03:49:45] Caerus: this_dude, absolutely and you should use it, a lot.
[03:50:22] Caerus: for instance, related to the .strip, it belongs to String class
[03:50:23] Caerus: https://ruby-doc.org/core-2.5.1/String.html
[03:51:22] this_dude: thats gonna make my life sooooo much easier
[03:51:29] Caerus: I´m also pretty sure there is a way to check the methos of each class either through irb or pry
[03:52:08] baweaver: >> String.methods.sample(5)
[03:52:09] ruby[bot]: baweaver: # => [:singleton_method, :public_method, :method_defined?, :instance_variable_set, :to_enum] (https://eval.in/1046230)
[03:52:47] Caerus: someobject.methods ...
[03:52:58] Caerus: oh beat me to it :P
[03:53:23] kapil___: has joined #ruby
[03:53:46] this_dude: wish i knew about that before ahahaha
[03:54:01] this_dude: well tysm guys gonna get treat myself to a drink now
[04:00:56] noobineer: has joined #ruby
[04:03:29] Freshnuts: has joined #ruby
[04:04:21] reber: has joined #ruby
[04:05:01] cagomez: has joined #ruby
[04:07:49] mcritchlow: has joined #ruby
[04:08:13] cagomez: has joined #ruby
[04:24:54] Emmanuel_Chanel: has joined #ruby
[04:35:13] alfiemax: has joined #ruby
[04:54:16] Jameser: has joined #ruby
[04:55:36] knightblader: has joined #ruby
[04:57:19] Creatornator: has joined #ruby
[04:58:22] ogres: has joined #ruby
[04:58:41] cgfbee: has joined #ruby
[04:59:18] this_dude: has joined #ruby
[05:00:59] this_dude: hey is .chars the same as .each_char?
[05:02:41] raulp: has joined #ruby
[05:05:24] eckhardt: has joined #ruby
[05:10:19] mojtaba: has joined #ruby
[05:26:22] this_dude: has joined #ruby
[05:26:28] this_dude: chat bugged out
[05:26:30] this_dude: need a little help
[05:26:46] this_dude: anyone on to assist?
[05:31:24] this_dude: oh didnt see your response lol
[05:32:01] this_dude: im creating a method that takes in array of integers and returns true or false as to whether the array is in ascending order
[05:33:08] this_dude: this is what i have so far
[05:33:21] this_dude: https://dpaste.de/Y8AC
[05:33:25] apeiros: has joined #ruby
[05:33:44] this_dude: and it works for the ones where it needs to return false
[05:33:58] this_dude: but its also returning false where it should return true
[05:34:17] this_dude: i think this is because of the statement && a[i] > a[i-1]
[05:34:32] this_dude: because if i==0 then i-1 == -1
[05:34:40] this_dude: and there is no -1 index value
[05:35:00] this_dude: so how can i make it so that it does that EXCEPT when the index value is already at 0
[05:35:03] Radar: >> a = [1,2,3,4,5]; a.sort == a
[05:35:04] ruby[bot]: Radar: # => true (https://eval.in/1046236)
[05:35:12] Radar: >> a = [5, 4, 3, 2, 1]; a.sort == a
[05:35:18] ruby[bot]: Radar: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[05:35:27] Radar: get outta town ruby[bot]
[05:36:15] this_dude: >> a = [5,4,3,2,1]; a.sort == a
[05:36:16] ruby[bot]: this_dude: # => false (https://eval.in/1046237)
[05:36:23] this_dude: you had spaces haha
[05:36:37] Radar: >> a = [5, 4, 3, 2, 1]; a.sort == a
[05:36:38] ruby[bot]: Radar: # => false (https://eval.in/1046238)
[05:36:41] Radar: Shouldn't matter.
[05:37:41] cadillac_: has joined #ruby
[05:38:02] Radar: Can we stop writing pseudo C code now?
[05:38:09] this_dude: literally one line of code did everything i was trying to do
[05:38:20] Radar: Yes. Your code looks like C.
[05:38:44] this_dude: for my exam i need to know how to do it without .sort and all that
[05:38:57] Radar: I still think that is a load of baloney.
[05:38:58] this_dude: cause that wasnt in the material given to study
[05:39:06] Radar: "Drive a car with your feet because lulzzzz"
[05:39:07] this_dude: thats the expectation
[05:39:15] this_dude: wait what XD
[05:39:17] Radar: with _only_ your feet
[05:39:31] this_dude: oh lmfao...like the flinstones?
[05:39:43] Radar: One foot on the steering wheel and the other on the pedals. Go on, try it.
[05:39:59] this_dude: i mean trust me i get you...its because i guess new coders arent expected to learn all of the possible methods in 10 days
[05:40:08] this_dude: idk something like that
[05:40:16] this_dude: and because we need to know how to do it the long way?
[05:40:23] Radar: Do you though? Really?
[05:40:23] this_dude: to understand what the easy way is doing
[05:40:41] this_dude: do i what..need to know the long way?
[05:41:14] Radar: P.S. your code isn't checking for nils.
[05:41:24] this_dude: well thats how the educational system is lol....in math class they always teach the long way first and make you do homework doing it the long way...then the next day they go "ok npow this is the easy way to do what you just learned" XD
[05:41:24] Radar: P.P.S. where are the minitest tests?
[05:41:37] this_dude: on the page im working on
[05:41:57] this_dude: https://dpaste.de/8xAV
[05:42:12] this_dude: is has those for every problem im doing
[05:42:36] this_dude: now to go look up what .sort does :>
[05:43:25] this_dude: https://ruby-doc.org/core-2.5.1/String.html#method-i-gsub is for strings
[05:43:30] this_dude: is there one for integers?
[05:43:37] this_dude: or arrays or whatever
[05:43:49] Radar: for arrays probably.
[05:44:38] this_dude: oh yup found the one for arrays
[05:48:20] mistym-: has left #ruby: ("Leaving...")
[05:48:26] mistym: has joined #ruby
[05:50:17] this_dude: hmm heres a crazy one
[05:51:04] this_dude: create a method that takes in an array of 10 numbers from 0-9 and returns it in the form of a telephone number i.e. "(123) 456-7890"
[05:54:53] this_dude: whats the method to insert a character at a designated index value in an array
[05:55:19] blood: is this a takehome test? god help you when you take a test for real
[05:55:31] this_dude: numbers[4].insert("-") for example
[05:55:39] this_dude: im doing practice problems dude
[05:55:44] this_dude: i just started the language
[05:55:47] this_dude: im not even in school
[05:56:06] this_dude: and i did take a test for real...failed twice...why do you think im practicing
[05:56:08] blood: start with a book for the basics
[05:56:21] this_dude: already know the "basics" they want me to know
[05:56:32] this_dude: now i need to know the more advanced stuff and only have 2 more days to learn it
[05:56:38] this_dude: im on a time constraint to pass an exam
[05:56:46] blood: 2 days to learn it? sounds like someone didnt pay attention =)
[05:56:53] this_dude: i was given 10 days
[05:57:01] this_dude: to learn enough to pass an exam
[05:57:03] blood: no school is going to give 10 days to learn a language
[05:58:03] this_dude: http://prntscr.com/kgwl2c
[05:58:31] blood: that doesn't prove anything
[05:58:40] blood: what course is this?
[05:59:00] this_dude: http://prntscr.com/kgwlcf
[05:59:48] this_dude: i studied and memorized all of the "prep resources" they provided
[06:00:02] this_dude: it nowhere near prepared me for the exam
[06:00:14] this_dude: so now im scrambling to memorize outside knowledge enough to pass
[06:00:21] this_dude: because i only have one more try to pass
[06:00:21] duderonomy: has joined #ruby
[06:00:23] blood: 12 week course, i would never trust anyone that tried this
[06:00:30] blood: this is like bootcamp
[06:00:40] blood: you cram a ton of information then lose it all
[06:00:40] this_dude: its a coding bootcamp im applying for
[06:00:48] blood: do it right and pick up a book
[06:01:04] this_dude: if i pass the exams, free tuition AND they help set me up with a job right out of the program
[06:01:41] blood: and why can you not pick up a book first then attempt this bootcamp?
[06:02:12] this_dude: because i didnt know what i was gonna have to learn until i applied...and now that i did apply the countdown has begun so its kinda too late for that :>
[06:02:24] this_dude: and i only have a couple days left
[06:02:32] this_dude: im been studying day in and day out
[06:02:56] blood: ok your choice =)
[06:03:40] this_dude: oh it is .insert
[06:03:46] this_dude: just wrote the syntax wrong
[06:05:08] camilasan: has joined #ruby
[06:10:11] this_dude: pshh got it
[06:10:32] this_dude: https://dpaste.de/8Uge
[06:11:58] this_dude: woah this is how they did it at a higher level...can anyone explain this?
[06:11:59] this_dude: '(%d%d%d) %d%d%d-%d%d%d%d' % array
[06:14:57] Nicmavr: has joined #ruby
[06:16:44] snickers: has joined #ruby
[06:33:19] blood: Using Nokogiri, the following doesn't find a match even though my xpath query is correct @document.xpath("/weblogic-web-app/session-descriptor/cookie-name").each do |el| el.content=value["value"] end
[06:33:33] blood: using an old version 1.7.2 since I'm forced to use Ruby 2.1.9 atm
[06:37:27] blood: interesting, using css worked
[06:37:33] blood: @document.css("/weblogic-web-app/session-descriptor/cookie-name").each but xpath does not
[06:43:01] dionysus69: has joined #ruby
[06:46:07] herbmillerjr: has joined #ruby
[06:51:58] za1b1tsu: has joined #ruby
[07:04:53] nowhere_man: has joined #ruby
[07:06:16] DTZUZO: has joined #ruby
[07:13:11] madhatter: has joined #ruby
[07:13:46] clemens3: has joined #ruby
[07:15:57] TomyWork: has joined #ruby
[07:17:31] vondruch: has joined #ruby
[07:22:21] yohji: has joined #ruby
[07:23:20] quazimodo: has joined #ruby
[07:25:39] mikecmpbll: has joined #ruby
[07:28:15] this_dude: im burnt..ill pick this up where i left off tomorrow
[07:28:48] snickers: has joined #ruby
[07:36:48] burgestrand: has joined #ruby
[07:39:12] sysvalve: has joined #ruby
[07:42:56] alex``: has joined #ruby
[07:50:39] mikecmpbll: has joined #ruby
[07:51:20] arup_r: has joined #ruby
[07:57:59] MuffinPimp: has joined #ruby
[08:03:07] cabotto: has joined #ruby
[08:17:29] DTZUZO: has joined #ruby
[08:17:47] jottr: has joined #ruby
[08:22:53] unCork: has joined #ruby
[08:32:43] heinrich5991: has joined #ruby
[08:33:50] aufi: has joined #ruby
[08:44:11] mojtaba: has joined #ruby
[08:53:28] p4p0l0: has joined #ruby
[08:54:55] snickers: has joined #ruby
[08:55:34] snickers: has joined #ruby
[09:01:16] dhollin3: has joined #ruby
[09:02:38] Sylario: has joined #ruby
[09:08:49] gix: has joined #ruby
[09:32:38] Mike11: has joined #ruby
[09:36:01] vondruch: has joined #ruby
[09:37:20] ferhaty: has joined #ruby
[09:37:33] alfiemax: has joined #ruby
[09:48:47] c0ncealed2: has joined #ruby
[10:00:16] psychicist__: has joined #ruby
[10:03:42] aufi: has joined #ruby
[10:06:47] sameerynho: has joined #ruby
[10:11:52] apeiros: has joined #ruby
[10:17:19] linucks: has joined #ruby
[10:21:56] za1b1tsu: has joined #ruby
[10:25:37] za1b1tsu: has joined #ruby
[10:32:48] desperek: has joined #ruby
[10:43:16] doubledup: has joined #ruby
[10:45:20] za1b1tsu: has joined #ruby
[10:47:07] Mike111: has joined #ruby
[10:49:11] Mike11: has joined #ruby
[10:59:24] howdoi: has joined #ruby
[11:06:38] doubledup: has joined #ruby
[11:09:40] snuz: has joined #ruby
[11:10:18] aufi: has joined #ruby
[11:12:23] arup_r: has joined #ruby
[11:14:40] gray_-_wolf: has joined #ruby
[11:22:00] ciro: has joined #ruby
[11:24:18] vondruch: has joined #ruby
[11:32:38] AJA4350: has joined #ruby
[11:37:11] sameerynho: has joined #ruby
[11:41:41] noobineer: has joined #ruby
[11:47:07] burgestrand: has joined #ruby
[11:59:16] alex``: has joined #ruby
[12:03:04] Dbugger: has joined #ruby
[12:04:01] r3my: has left #ruby: ()
[12:05:53] Jameser: has joined #ruby
[12:10:56] jcalla: has joined #ruby
[12:22:32] snuz: has joined #ruby
[12:23:58] salasrod: has joined #ruby
[12:26:04] MyMind: has joined #ruby
[12:33:08] GodFather: has joined #ruby
[12:42:58] za1b1tsu: has joined #ruby
[12:59:38] fmcgeough: has joined #ruby
[12:59:40] tj-: has joined #ruby
[13:04:15] User458764: has joined #ruby
[13:10:42] Inline: has joined #ruby
[13:13:45] bmurt: has joined #ruby
[13:19:20] DarthGandalf: has joined #ruby
[13:24:15] alex``: has joined #ruby
[13:30:05] twe4ked: has joined #ruby
[13:35:26] za1b1tsu: has joined #ruby
[13:42:58] m27frogy: has joined #ruby
[13:43:09] gheegh: has joined #ruby
[13:56:54] zerowaitstate: has joined #ruby
[13:58:20] zerowaitstate: how do you write an rspec mock that always returns a specific value for a specific input, regardless of the number of times it is called?
[14:02:32] balo: zerowaitstate: what do you mean? double('MyClass', foo: :bar) ?
[14:02:39] burgestrand: has joined #ruby
[14:04:36] vondruch: has joined #ruby
[14:06:36] rippa: has joined #ruby
[14:07:03] chouhoulis: has joined #ruby
[14:15:48] zerowaitstate: balo: I mean I have a factory method on a base class that accesses a database, and I need it to always return the same object for the same parameters (since the test runs without a database)
[14:17:33] balo: allow_any_instance_of(MyClass).to receive(:my_factory_method).and_return(same_object)
[14:18:04] balo: in general i don't like the "allow_any_instance_of" but sometimes it's useful. and maybe you can just use allow(my_object).to receive....
[14:18:21] balo: depending on how that factory method is implemented and how do you access it
[14:18:56] balo: or it can be that i still don't get the issue :)
[14:19:02] agent_white: has joined #ruby
[14:19:23] zerowaitstate: that may be all that is necessary. I'm still new to RSpec and the DSL is confusing me a bit
[14:19:27] snickers: has joined #ruby
[14:21:16] zerowaitstate: actually the problem I have with receive.and_return is that it always returns a given sequence. So, if you pass an array in to #and_return, the same sequence of objects is always returns, regardless of the arguments supplied to the method
[14:21:33] akaiiro: has joined #ruby
[14:21:53] zerowaitstate: that makes the test brittle, because I have to know in what order each call to the factory method happens in the code.
[14:23:45] zerowaitstate: it would be super helpful to be able to create a simple hash of inputs to results and pass that to #and_return, but that doesn't appear to be an option
[14:27:45] moei: has joined #ruby
[14:31:55] p4p0l0: has joined #ruby
[14:34:37] gray_-_wolf: was on tracker or ml ever discussed option of adding precompiled (preparsed) ruby files into mri? Something like python's `.pyc` files? I didn't find anything so I'm trying to here
[14:38:48] drale2k_: has joined #ruby
[14:38:53] burgestrand: has joined #ruby
[14:39:22] darix: gray_-_wolf: the new jit added for 2.6 will bring you something similar
[14:41:27] za1b1tsu: has joined #ruby
[14:41:30] gray_-_wolf: hm? I thought that JIT is about optimizations, not reducing parsing time. I'm looking at `ruby --help` of current trunk and I'm not seeing anything related to this...
[14:41:35] chouhoulis: has joined #ruby
[14:41:37] gray_-_wolf: where could I find more on this?
[14:42:00] balo: zerowaitstate: hmm, i think now i understand the issue. you rely on the consecutive return values... i've never used it, never needed it. How would you refactor your code to make it more easy to test?
[14:42:08] darix: gray_-_wolf: it will store the compiled version of your ruby files if it is jit worthy
[14:42:16] darix: gray_-_wolf: are you sure the parse time is your problem?
[14:42:21] balo: in general, rarely a good idea to have such complicated mocking
[14:43:38] felix_vs: has joined #ruby
[14:43:54] gray_-_wolf: darix: well... not whole problem but part of. I have few very simple scripts which do some basic stuff but pull lot of things in.. based on my profiling the parsing is about 20% of the script run; I know python solves this via .pyc files so was looking if something like that is available for ruby
[14:48:05] darix: gray_-_wolf: not sure we have something like that.
[14:48:33] chouhoulis: has joined #ruby
[14:49:21] ineb: zerowaitstate: balo: do i understand something wrong? cant you do expect(mock).to receive(:foo).with(bar).and_return(baz)
[14:50:40] gray_-_wolf: hm maybe I'll try to write it, could be interesting exercise
[14:52:12] balo: ineb: you can, the problem is - if i understand it correctly that he the code relies on consecutive return values of the mock. and he feels it wrong to depend on the order and wanted to match the arguments with the return values. like passing it as a hash somehow but for the same method as input output list. https://github.com/rspec/rspec-mocks#consecutive-return-values
[14:56:41] ineb: zerowaitstate: balo: i think balo already answered the question. if return values based on specific input is required, it needs to ne listed explicitly and not as return sequence
[14:57:16] ineb: for every possible input, a return value needs to be declared
[15:02:08] balo: ah, yeah, that can work actually. expect(MyClass).to receive(:my_builder).with(:myarg_1).and_return(my_arg_object_1)
[15:02:43] balo: and one line for every arg-return pair?
[15:02:57] ineb: the mock for that can be build with a helper function which provides the desired functionality from zerowaitstate to build the mock from a hash
[15:03:34] balo: yeah. anyway, for me this test case sounds a bit complicated
[15:04:06] ineb: it is. but can be used to mock subsequent db calls for every test needed
[15:04:13] ineb: if you dont want integration tests against a real db
[15:04:55] ineb: i have used it aswell for mocking http calls
[15:12:47] ciro: has joined #ruby
[15:14:13] Emmanuel_Chanel: has joined #ruby
[15:20:41] clemens3: has joined #ruby
[15:33:25] apeiros_: has joined #ruby
[15:34:00] AJA4350: has joined #ruby
[15:34:17] SeepingN: has joined #ruby
[15:41:55] mroutis: has joined #ruby
[15:43:48] polishdub: has joined #ruby
[15:44:39] mroutis: has joined #ruby
[15:51:47] User458764: has joined #ruby
[15:57:30] impermanence: has joined #ruby
[15:57:46] cagomez: has joined #ruby
[15:58:59] apeiros_: has joined #ruby
[16:06:13] Rapture: has joined #ruby
[16:07:12] agent_white: has joined #ruby
[16:11:02] hfp_work: has joined #ruby
[16:11:59] apeiros_: has joined #ruby
[16:15:50] AJA4351: has joined #ruby
[16:16:48] maryo: has joined #ruby
[16:17:53] jcarl43: has joined #ruby
[16:20:58] jottr: has joined #ruby
[16:22:23] AJA4350: has joined #ruby
[16:23:58] orbyt_: has joined #ruby
[16:28:30] snuz: has joined #ruby
[16:30:06] JamJam_kid: has joined #ruby
[16:31:05] alfiemax: has joined #ruby
[16:40:46] Eiam: has joined #ruby
[16:43:17] samort7: has joined #ruby
[16:44:14] samort14: has joined #ruby
[16:44:29] samort14: How do I know what gems are included in the Standard Library by default?
[16:46:14] armyriad: has joined #ruby
[16:47:19] mroutis: samort14, they are "modules", afair, you can get an idea of the modules reading the docs: http://ruby-doc.org/stdlib-2.5.1/
[16:48:04] samort14: mroutis: Ah, thank you! Exactly what I was looking for!
[16:48:04] mroutis: I don't think those modules are packaged as gems
[16:48:20] AJA4350: has joined #ruby
[16:48:22] mroutis: yw, samort14 ;)
[16:48:50] cthulchu_: has joined #ruby
[16:51:31] snuz: has joined #ruby
[16:51:40] samort14: mroutis: So If I want to use any of those modules, I just need to 'require' them right?
[16:51:49] mroutis: yes, that's right
[16:52:20] alfiemax: has joined #ruby
[16:52:26] samort14: mroutis: Ah, ok. Now I am understanding the difference between modules and gems
[16:52:28] sameerynho: has joined #ruby
[16:52:29] orbyt_: has joined #ruby
[16:54:27] mroutis: cool! if that helps, you can read more about gems here: https://guides.rubygems.org/what-is-a-gem/
[16:54:33] jottr: has joined #ruby
[16:54:47] Nicmavr: has joined #ruby
[16:55:55] samort14: mroutis: Awesome! Thanks again!
[16:55:58] User458764: has joined #ruby
[16:58:09] User458764: has joined #ruby
[16:59:52] User458764: has joined #ruby
[17:01:53] User458764: has joined #ruby
[17:01:59] ohcibi: has joined #ruby
[17:02:33] havenwood: samort14: There are two types of gems that ship with Ruby, bundled gems and default gems.
[17:02:46] havenwood: samort14: (The "bundled" name has nothing to do with Bundler.)
[17:03:34] havenwood: samort14: Bundled gems are not maintained by Ruby core and can be uninstalled with the `gem uninstall` command.
[17:03:35] havenwood: samort14: Default gems are maintained by Ruby core and cannot be uninstalled.
[17:04:18] havenwood: samort14: Recent versions of Ruby have seen large increases in the number of gems default gems that are extracted and gemified from the standard library.
[17:04:47] havenwood: samort14: The bundled gems are did_you_mean, minitest, net-telnet, power_assert, rake, test-unit and xml-rpc.
[17:05:35] havenwood: samort14: So if you wanted to, you could delete them all after you install Ruby: gem uninstall did_you_mean minitest net-telnet power_assert rake test-unit xml-rpc
[17:06:27] havenwood: samort14: In Ruby 2.4, there were just a similar number of default gems. The amount nearly tripled in Ruby 2.5 as the efforts to gemify the standard library gained steam.
[17:07:34] havenwood: samort14: In Ruby 2.5, default gems include bigdecimal, io-console, json, openssl, psych, rdoc, rubygems, webrick, cmath, csv, date, dbm, gdbm, sdbm, etc, fcntl, fiddle, fileutils, ipaddr, scanf, stringio, strscan and zlib.
[17:07:54] Creatornator: has joined #ruby
[17:08:05] samort14: havenwood: ah wow, really interesting! I feel like I have been looking for a straightforward explanation on this stuff for a while but couldn't find it anywhere
[17:08:08] mroutis: havenwood: today I learned ^; that's interesting
[17:08:12] havenwood: (Only the first eight of which were default gems in Ruby 2.4.)
[17:08:26] felix_vs: has joined #ruby
[17:09:34] havenwood: More of the standard library is also being gemified and removed from Ruby - which has resulted in gems like curses and tk.
[17:12:25] samort14: Ah! This makes so much sense! I was getting an error: `Unable to activate xml-to-json-1.0.2, because json-2.1.0 conflicts with json` because I was requiring 'xml/to/json' and didn't realize 'json' was a default gem
[17:15:26] mikecmpbll: has joined #ruby
[17:15:41] darkhanb: has joined #ruby
[17:16:15] samort14: So in my situation, since 'json' is a default gem, it cannot be uninstalled, so there must be a way for me to be able to use 'xml/to/json' without it conflicting, right? Like changing its namespace?
[17:16:48] havenwood: samort14: You can upgrade default gems without updating Ruby.
[17:18:03] havenwood: That's one of the nice things about gemifying the stdlib. You can just update a gem like bigdecimal if it has a CVE, rather than having to update Ruby itself to get the fix.
[17:18:23] havenwood: But yeah, you can't remove them.
[17:18:25] samort14: When you say 'update', what do you mean by that?
[17:18:34] havenwood: samort14: gem update json
[17:18:44] havenwood: samort14: You can have multiple versions of the JSON gem installed.
[17:18:45] [reed]: has joined #ruby
[17:21:23] samort14: wait, but I'm trying to use this gem https://github.com/digitalheir/ruby-xml-to-json and the conflict is happening with the default 'json' gem. They're not the same gem, right?
[17:22:12] havenwood: samort14: The issue is coming from this dep: https://github.com/digitalheir/ruby-xml-to-json/blob/master/xml-to-json.gemspec#L38
[17:22:35] samort14: Ooooh! It requires an older version of json!
[17:22:42] samort14: Wow! You have a good eye!
[17:23:15] bmurt: has joined #ruby
[17:24:20] havenwood: samort14: JSON 1.8 used to not work with Ruby 2.4 or newer, but iir version 1.8.4 or later does work. Try: gem install json -v '~> 1'
[17:24:34] tty: has joined #ruby
[17:25:28] samort14: Ok, quick question - If I want to share the program that I am writing with other people, how do I communicate with them what version of each gem they should be installing? Should I use a Gemfile instead of "gem install"ing things manually?
[17:26:01] havenwood: samort14: PS - This is all the code that this gem provides: https://github.com/digitalheir/ruby-xml-to-json/blob/master/lib/xml/to/json.rb#L5-L37
[17:26:58] havenwood: samort14: You can just manually `to_hash.to_json` or implement just what you need. It should only be a few lines.
[17:28:40] havenwood: samort14: If you're sharing your code as a gem, you specify the dependencies in the gemspec. If you're sharing your code as an app, you specify the exact versions of the dependencies in the Gemfile.lock, which is programatically created from the deps you specify in the Gemfile.
[17:29:35] havenwood: samort14: It's common with a gem to have a Gemfile, but it'll often just have the line `gemspec`, which means defer to the gemspec file when bundling.
[17:29:45] havenwood: samort14: With gems, we add the Gemfile.lock to the .gitignore.
[17:29:59] tdy: has joined #ruby
[17:30:05] havenwood: With apps, you ship the Gemfile.lock so every dev is using the exact same gems and versions when running the app.
[17:30:24] samort14: havenwood: Ah, wow, this is all super useful information! Thank you guys so much!
[17:30:33] havenwood: samort14: No prob. Happy coding!
[17:31:01] havenwood: samort14: Here's an article Yehuda wrote a while back: https://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
[17:32:09] samort14: +1000 I'm definitely going to use that!
[17:32:22] jcarl43: has joined #ruby
[17:32:48] baweaver: ACTION wanders in
[17:32:54] samort14: I gotta say, people in the Ruby community are like some of the most helpful compared to a lot of the other languages I have learned
[17:33:14] snickers: has joined #ruby
[17:34:40] baweaver: >> h = {a: 1, b: 2, c: 3}; h.keys.map(&h)
[17:34:42] ruby[bot]: baweaver: # => [1, 2, 3] (https://eval.in/1046586)
[17:34:47] baweaver: ACTION slowly backs away
[17:35:47] havenwood: baweaver: Ruby 2.6: {a: 1, b: 2, c: 3}.then { |h| h.keys.map &h } #=> [1, 2, 3]
[17:36:13] havenwood: baweaver: That's a convoluted way to say "values"!
[17:36:31] baweaver: Want to know where it becomes useful?
[17:36:52] havenwood: Case statements?
[17:36:56] havenwood: baweaver: where?
[17:37:35] havenwood: <3 #filter and #then aliases in 2.6
[17:37:48] havenwood: I know some folk don't like #then, but wheeee!
[17:37:59] baweaver: >> Point = Struct.new(:x, :y); origin = Point.new(0, 0); def destructure(v, &fn) yield *fn.parameters.map(&:last).map(&v.to_h) end; destructure(origin) { |x, y| x + y }
[17:38:04] ruby[bot]: baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[17:38:12] baweaver: >> Point = Struct.new(:x, :y); origin = Point.new(0, 0); def destructure(v, &fn) yield *fn.parameters.map(&:last).map(&v.to_h) end; destructure(origin) { |x, y| x + y }
[17:38:17] ruby[bot]: baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[17:38:23] baweaver: havenbot wins.
[17:39:52] cadillac_: has joined #ruby
[17:56:48] snuz: has joined #ruby
[17:57:17] nowhere_man: has joined #ruby
[18:01:28] mroutis: has joined #ruby
[18:06:51] snuz: has joined #ruby
[18:07:02] tag: has joined #ruby
[18:08:52] marius: has joined #ruby
[18:10:19] akaiiro: has joined #ruby
[18:10:52] r29v: has joined #ruby
[18:22:24] User458764: has joined #ruby
[18:24:23] User458764: has joined #ruby
[18:26:29] User458764: has joined #ruby
[18:27:20] this_dude: has joined #ruby
[18:27:31] this_dude: hey guys goodmornin
[18:28:23] User458764: has joined #ruby
[18:30:23] User458764: has joined #ruby
[18:31:22] marius: has joined #ruby
[18:32:33] User458764: has joined #ruby
[18:34:33] User458764: has joined #ruby
[18:34:33] ellcs: has joined #ruby
[18:36:11] bmurt: has joined #ruby
[18:36:33] User458764: has joined #ruby
[18:38:11] samort14: Good morning :)
[18:39:01] User458764: has joined #ruby
[18:39:36] tj-: has joined #ruby
[18:40:43] jcarl43: has joined #ruby
[18:41:01] User458764: has joined #ruby
[18:43:02] User458764: has joined #ruby
[18:44:56] jottr: has joined #ruby
[18:45:00] User458764: has joined #ruby
[18:47:00] User458764: has joined #ruby
[18:47:02] weaksauce: has joined #ruby
[18:47:29] GodFather: has joined #ruby
[18:49:06] marius: has joined #ruby
[18:53:38] dviola: has joined #ruby
[18:54:34] SirFunk: has joined #ruby
[18:55:50] AJA4350: has joined #ruby
[18:56:13] snuz: has left #ruby: ()
[18:56:53] PettanShoutaKun: has joined #ruby
[18:58:59] PettanShoutaKun: https://gist.github.com/TheeRFG/2dfe526b7bd7c2c15b337abfc73ddf90 will something like this give me time in seconds?
[19:01:57] this_dude: its loading just a sec
[19:02:15] snuz: has joined #ruby
[19:03:37] this_dude: good question
[19:03:40] PettanShoutaKun: provided that only seconds have passed between those two time periods?
[19:04:10] this_dude: yeah cause if its greater than a 60 minute difference
[19:04:17] this_dude: it'll return it in hours:minutes
[19:04:29] PettanShoutaKun: awesome, thank you!
[19:05:57] this_dude: do me a favor...
[19:06:07] this_dude: take a look at my code and see if any obvious errors stick out?
[19:06:14] snuz: has joined #ruby
[19:06:49] alfiemax: has joined #ruby
[19:07:10] this_dude: https://dpaste.de/74aQ
[19:07:40] this_dude: the method should take in a string of numbers and return a digital root
[19:07:57] this_dude: (the sum of all characters repeated until youre left with a one digit integer)
[19:08:13] this_dude: I.E. 942 returns 6
[19:12:28] dionysus69: has joined #ruby
[19:15:33] ineb: this_dude: or [1,2,9,2,3].inject { |sum, n| new_sum = sum + n; break sum if new_sum > 9; new_sum ; }
[19:15:59] ineb: >> [9,4,2].inject { |sum, n| new_sum = sum + n; break sum if new_sum > 9; new_sum ; }
[19:16:00] ruby[bot]: ineb: # => 9 (https://eval.in/1046609)
[19:16:25] this_dude: that returned an incorrect response^
[19:16:35] ineb: right ^^ u said 6
[19:17:11] this_dude: this one is giving me some trouble haha
[19:17:19] this_dude: been stuck since yesterday
[19:19:44] this_dude: i think the error in yours is the "break sum if new_sum > 9"
[19:19:53] this_dude: cause i need it to rerun the loop if its greater than 9
[19:20:41] this_dude: break sum if new_sum.length == 1
[19:21:12] baweaver: What's the link to the question?
[19:21:35] baweaver: input.chars.map(&:to_i)
[19:21:35] this_dude: http://www.codewars.com/kata/sum-of-digits-slash-digital-root/train/ruby
[19:22:17] havenwood: 942.digits.sum #=> 15
[19:22:39] this_dude: but then i need it to do that again^
[19:22:42] this_dude: to give me 6
[19:22:50] havenwood: 15.digits.sum #=> 6
[19:23:00] this_dude: im having trouble setting the parameter of "stop when result.length == 1"
[19:24:13] ineb: havenwood: nice one
[19:24:16] baweaver: havenwood: when was digits introduced?
[19:24:21] ineb: should be easy then
[19:24:24] havenwood: baweaver: 2.4
[19:24:41] baweaver: Now why did RVM put me back on 2.3....
[19:24:42] this_dude: i kinda got it?
[19:24:45] this_dude: but not quite
[19:24:54] this_dude: n.digits { |sum, n| new_sum = sum + n; break sum if new_sum.length == 1; new_sum ; }.join.to_i
[19:25:03] this_dude: something is wrong here
[19:25:05] this_dude: not sure what
[19:25:20] havenwood: >> n = 942; loop { break n if n.digits.one?; n = n.digits.sum }
[19:25:21] ruby[bot]: havenwood: # => undefined method `digits' for 942:Fixnum (NoMethodError) ...check link for more (https://eval.in/1046611)
[19:25:58] baweaver: def digital_root(n) n.digits.sum.yield_self { |s| s.digits.size == 1 ? s : digital_root(s) } end; digital_root(942)
[19:26:22] baweaver: To understand recursion you must first understand recursion.
[19:26:49] baweaver: ah, right, `one?`
[19:27:04] baweaver: def digital_root(n) n.digits.sum.yield_self { |s| s.digits.one? ? s : digital_root(s) } end; digital_root(942)
[19:27:08] marius: has joined #ruby
[19:27:09] this_dude: idk whats going on
[19:27:46] baweaver: Do you know what factorial numbers are?
[19:27:48] this_dude: guys i need to know how to write this without maps and stuff XD
[19:28:08] this_dude: yeah...5*4*3*2*1
[19:28:13] baweaver: That's a silly constraint.
[19:28:27] this_dude: well its whats needed for my exam remember .-.
[19:28:39] baweaver: Where does it say you can't though?
[19:28:44] this_dude: https://dpaste.de/0dEA
[19:28:46] baweaver: It says you don't _need_ them
[19:29:05] baweaver: not that you _can't_ use them.
[19:29:24] this_dude: thats what i have so far^
[19:29:28] this_dude: and you're right
[19:29:34] baweaver: So would it be fair to say Factorial 5 (5!) could be expressed as 5 * 4! ?
[19:29:38] this_dude: but for time constraint's sake
[19:29:47] this_dude: shouldnt i just learned to do it the long way
[19:30:11] baweaver: That's the trick though
[19:30:25] this_dude: cause i have no idea what "def digital_root(n) n.digits.sum.yield_self { |s| s.digits.one? ? s : digital_root(s) } end; digital_root(942)"
[19:30:34] baweaver: If you know the type you're operating on (Array, Enumerable, Hash, String, Integer) you can find its methods
[19:30:48] baweaver: and if you can find those you can get those methods
[19:31:10] this_dude: i bookmarked the dictionaries of methods for each of those by the way hehehe
[19:31:31] baweaver: >> def factorial(n) n < 2 ? n : n * factorial(n - 1) end; factorial(5)
[19:31:32] ruby[bot]: baweaver: # => 120 (https://eval.in/1046612)
[19:31:54] baweaver: If n is less than 2, return n, otherwise return n multiplied by the factorial of n minus one.
[19:32:02] havenwood: Enumerator.generate(942) { |n| raise StopIteration if n.digits.one?; n.digits.sum }.reverse_each.first #=> 6
[19:32:23] this_dude: couldnt you just...if n is less than 2, return n, otherwise return factorial of n
[19:32:31] baweaver: so 5! -> 5 * 4! -> 5 * 4 * 3! -> 5 * 4 * 3 * 2! -> 5 * 4 * 3 * 2 * 1
[19:32:54] this_dude: what is "enumerator"?
[19:33:10] baweaver: you take a problem you don't know the answer to and break it into smaller concepts until you do know an answer
[19:33:11] havenwood: Enumerator.generate(942) { |n| n.digits.sum }.find { |n| n.digits.one? } #=> 6
[19:33:13] this_dude: and "raise stopiteration"
[19:33:26] havenwood: this_dude: Stuff.
[19:33:39] baweaver: generate isn't even in core is it?
[19:33:40] this_dude: ok but like
[19:33:44] this_dude: youre blowing my mind
[19:33:47] havenwood: baweaver: Nope, proposed for 2.6: https://github.com/zverok/enumerator_generate#readme
[19:33:56] baweaver: proposed, yes
[19:34:28] this_dude: ahahahahaha i tried to copy paste that and got
[19:34:37] this_dude: "endefined method "generate"
[19:35:01] havenwood: this_dude: The Enumerator#generate method isn't in Ruby yet. It was proposed for 2.6.
[19:35:13] this_dude: so how do i do this in ruby then
[19:35:30] this_dude: i want to understand the long way to do it
[19:35:34] this_dude: then learn the easy way
[19:35:47] this_dude: cause i dont get why my long way isnt working
[19:35:55] this_dude: https://dpaste.de/74aQ
[19:36:19] this_dude: it works for some, and not for others
[19:36:21] havenwood: this_dude: In current Ruby you can write it with an Enumerable like: Enumerator.new { |yielder| n = 942; loop { yielder << n; n = n.digits.sum } }.find { |n| n.digits.one? } #=> 6
[19:36:48] this_dude: ACTION is very confused and mindblown 
[19:36:57] this_dude: currently processing that..
[19:37:05] havenwood: this_dude: In Ruby you can make your own Enumerator collections.
[19:37:41] havenwood: this_dude: https://docs.ruby-lang.org/en/2.5.0/Enumerator.html
[19:37:56] this_dude: oh wait can i just ...while n.length>1; n = n.digits.sum; return n
[19:38:03] havenwood: this_dude: yup
[19:38:12] this_dude: i feel stupid..again
[19:39:15] this_dude: but what if n is just..7
[19:39:18] this_dude: it'll return nil
[19:39:21] this_dude: how do i stop that?
[19:39:39] havenwood: baweaver: If all goes well, in 2.6...!: Enumerator.generate(942, &:digits << :sum).find(&:digits << :one?) #=> 6
[19:40:06] havenwood: Actually, I should write a quick gem for the shovel proc compositions: https://gist.github.com/havenwood/d305b42f5b542e9de1eaa8e56ba6bdd7
[19:40:42] havenwood: That's a nice thing about Ruby, we can easily implement these features in a few lines until they're formally introduced.
[19:41:51] this_dude: so it worked for all but one of my minitests
[19:42:35] this_dude: https://dpaste.de/jmST
[19:43:15] this_dude: nevermind..typoed the minitest..it works
[19:43:27] this_dude: i feel incompetent because i struggled on that for so long
[19:44:19] this_dude: i cant find an article on .digits
[19:46:34] havenwood: this_dude: Here's my solution: https://gist.github.com/havenwood/b6d55b412fbf583758c91b8ee339a822
[19:47:14] this_dude: found the article nvm
[19:47:37] this_dude: https://ruby-doc.org/core-2.4.0/Integer.html
[19:47:41] havenwood: I love we can make this work in ~20 lines...:
[19:47:42] havenwood: Enumerator.generate(942, &:digits << :sum).find(&:digits << :one?)
[19:48:09] this_dude: so much code
[19:49:20] havenwood: this_dude: That's pretty little code considering it implements function composition and a new way to generate an Enumerator!
[19:49:43] this_dude: omg so...i work at a steakhouse and im off the clock here studying..this lady just came..TO A STEAKHOUSE...and asked if we have a vegetarian menu
[19:49:45] this_dude: we dont lmao.
[19:50:04] havenwood: this_dude: None of the cows were vegetarians?
[19:50:19] this_dude: I'll tell her that
[19:50:33] this_dude: "Ma'am all of our cows were vegetarians is that what you meant?"
[19:50:57] this_dude: can i call you shannon
[19:51:09] havenwood: this_dude: Here's how the actual Enumerator is implemented in TruffleRuby, which is the Ruby most broadly implemented in Ruby: https://github.com/oracle/truffleruby/blob/master/src/main/ruby/core/enumerator.rb
[19:51:34] eam: has joined #ruby
[19:51:37] maryo: has joined #ruby
[19:51:41] this_dude: i feel like if i read that ill just end up more confused than before so ill stick to my basics xD
[19:52:14] havenwood: this_dude: Yeah, no need to look into implementation details unless you're just curious and have lots of time.
[19:52:34] this_dude: maybe later
[19:53:51] maryo: While starting the dashing service one of the job is giving out an exception (https://dpaste.de/Z8h7) here is the entire job code (https://dpaste.de/gFqf) some pointers would be appreciated
[19:55:03] this_dude: oh geeze this problem lol "Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char."
[19:55:04] mroutis: has joined #ruby
[19:55:16] spiette: has joined #ruby
[19:56:22] solidsnack: has joined #ruby
[19:56:39] this_dude: so apparently its not .scan..what would the method for a string be to see if any of the characters match a designated value?
[19:56:40] baweaver: maryo: What does the first line of the error say?
[19:57:46] maryo: baweaver, first line of the error? it says "scheduler caught exception:
[19:58:02] baweaver: Now the second line
[19:58:22] mojtaba: has joined #ruby
[19:58:35] maryo: baweaver, here it is undefined method `[]' for nil:NilClass
[19:58:38] baweaver: >> nil['nope']
[19:58:43] ruby[bot]: baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[19:58:56] baweaver: Does that error look familiar?
[19:59:21] baweaver: ( havenwood - Oh I know )
[19:59:42] maryo: baweaver, yep but I am wondering from where I am getting that nil value
[20:00:43] baweaver: from get_build_info
[20:01:18] chouhoulis: has joined #ruby
[20:01:59] maryo: baweaver, you mean this line https://dpaste.de/gFqf#L94 ?
[20:02:42] baweaver: Keep tracing it backwards until you find where bad info got into the pipeline
[20:04:39] maryo: baweaver, Is it possible to get the value of result for debugging purpose ? like p result ? by adding it to line 155
[20:06:28] baweaver: You could certainly try it.
[20:06:32] 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
[20:06:35] baweaver: That may help
[20:07:23] this_dude: i think im using .count wrong lol
[20:07:39] maryo: thank you baweaver o/
[20:08:42] this_dude: https://dpaste.de/uRhJ
[20:09:51] baweaver: you're missing an end as well
[20:10:26] this_dude: yeah i saw that hah
[20:10:30] baweaver: So you want to get a count of xs and os?
[20:10:33] this_dude: but am i using .count wrong or something?
[20:11:04] beefjoe: has joined #ruby
[20:11:08] baweaver: Contrived 30 second implementation: str.downcase.chars.group_by(&:itself).values.map(&:count).uniq.one?
[20:11:20] fmcgeough: has joined #ruby
[20:11:26] tdy: has joined #ruby
[20:12:01] this_dude: why you gotta make everything so complicated D:
[20:12:18] this_dude: so high level**
[20:12:30] baweaver: Nicer way: counts = str.downcase.chars.each_with_object(Hash.new(0)) { |c, counts| counts[c] += 1 }; counts[0] == counts[1]
[20:13:27] baweaver: 2.6+, if accepted: str.downcase.chars.histogram.values.uniq.one?
[20:13:56] this_dude: according to ruby-doc.org .count is used like so
[20:13:57] this_dude: http://prntscr.com/kh6wsk
[20:14:18] this_dude: thats the image they provide
[20:17:15] this_dude: oh to include multiple letters you just... .count "xX" .count "oO"
[20:17:17] oncall-pokemon: has joined #ruby
[20:17:28] this_dude: but my comparison statement returns an error
[20:20:07] this_dude: https://dpaste.de/62Y7
[20:20:11] this_dude: whats wrong here lol
[20:20:16] this_dude: doesnt make sense to me
[20:22:16] GodFather: has joined #ruby
[20:22:55] this_dude: nvm i got it
[20:23:19] this_dude: by doing it the long way https://dpaste.de/9Pi4
[20:24:35] this_dude: str.downcase.count('x') == str.downcase.count('o') was the answer
[20:24:41] this_dude: but i tried that and got an error...
[20:30:24] eckhardt_: has joined #ruby
[20:34:41] gheegh: has joined #ruby
[20:36:13] this_dude: how do you coerce a range into integers
[20:36:27] this_dude: [a..b].sum.to_i
[20:36:34] this_dude: or something like that
[20:37:46] mojtaba: has joined #ruby
[20:42:09] NightMonkey: has joined #ruby
[20:43:16] apeiros: >> (10..20).sum # this_dude
[20:43:22] ruby[bot]: apeiros: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[20:43:28] this_dude: already found it
[20:43:37] apeiros: meh, we really need something more reliable than eval.in :(
[20:43:43] this_dude: its (a..b).to_a.sum
[20:44:00] apeiros: that's less efficient
[20:44:05] this_dude: >> (10..20).to_a.sum
[20:44:11] ruby[bot]: this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[20:44:12] apeiros: you can just drop the .to_a
[20:44:22] this_dude: gave me an error when i did
[20:44:29] apeiros: which ruby version?
[20:44:42] this_dude: idk im on codewars.com
[20:44:43] apeiros: also what error exactly?
[20:44:55] this_dude: oh wait not its not giving me that error wtf dude lol
[20:45:44] apeiros: also, sum of a range can be calculated directly ;-)
[20:46:10] apeiros: ACTION wonders whether Range#sum special cases that
[20:46:31] this_dude: the range isnt given
[20:46:36] this_dude: only two integers
[20:46:46] this_dude: i have to make the range inside my method
[20:46:59] this_dude: "Given two integers a and b, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return a or b."
[20:47:48] apeiros: hm, now I wonder whether the direct calculation also works for negative numbers…
[20:47:59] this_dude: i have a problem though
[20:48:05] this_dude: my code is working for all except one minitest
[20:48:24] this_dude: its returning nil for some reason
[20:48:31] apeiros: do you create a range 5..-1 from it?
[20:48:57] this_dude: https://dpaste.de/FMda
[20:49:15] this_dude: i created an if statement for if the second integer is the smaller one
[20:49:25] this_dude: it should take that into account idk whats going wrong
[20:49:46] havenwood: this_dude: (42..1).size #=> 0
[20:50:25] apeiros: looks to me like your code is correct
[20:50:28] this_dude: my code should be creating a range from -1 to 5
[20:50:37] this_dude: then wtf lol
[20:50:42] apeiros: you could simplify it since (n..n).sum == n
[20:50:54] this_dude: oh i ran it agin
[20:50:58] this_dude: again* and now it worked
[20:51:23] this_dude: oh you right
[20:51:40] havenwood: >> (42..42).sum
[20:51:44] this_dude: wait thats it
[20:51:46] apeiros: i.e. `a,b = b,a if b < a; (a..b).sum` is sufficient
[20:51:47] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: OpenURI::HTTPError:500 Internal Server Error
[20:52:00] this_dude: when i remove the " elsif a == b "
[20:52:05] this_dude: line it gives me the nil
[20:52:10] this_dude: for 5 and -1
[20:52:22] apeiros: because you still have a condition
[20:52:42] apeiros: none of your branches is it
[20:53:07] this_dude: my dogs name is duderonomy LOL
[20:53:32] this_dude: so it should execute line 4 no??
[20:53:41] apeiros: `if cond1; stuff; elsif cond2; suff2; end` if neither cond1 nor cond2 is met, none of the `stuff` branches is executed and it evaluates as nil
[20:54:17] this_dude: but thats what im saying...doesnt 5 and -1 meet the condition of line 4 https://dpaste.de/FMda#L
[20:54:18] havenwood: this_dude: Range.new(*[41, 1].sort).sum #=> 861
[20:55:06] apeiros: this_dude: yes. I thought you were talking about a == b giving you nil.
[20:55:35] this_dude: when i dont include that line the minitest using (5,-1) returns nil
[20:55:39] this_dude: no idea why
[20:56:25] apeiros: paste the code
[20:56:47] this_dude: the minitest code?
[20:57:19] this_dude: https://dpaste.de/FMda#L is my code
[20:57:28] this_dude: Test.assert_equals(get_sum(5,-1),14)
[20:57:34] havenwood: this_dude: both. a gist can have multiple files and be updated.
[20:57:47] this_dude: is the minitest code that returns nil if i take out lines 6 and 7
[20:58:43] apeiros: this_dude: if you take out line 6 and 7, your method will be broken. but it should still return the correct result for 5,-1
[20:59:01] this_dude: exactly my poiny
[20:59:06] ellcs: has joined #ruby
[20:59:07] this_dude: point* no idea whats going on
[20:59:09] apeiros: (and does so for me)
[20:59:12] havenwood: this_dude: To clarify, you want to do `(b..a).sum` when b is smaller, and otherwise, for all cases, do `(a..b).sum`?
[20:59:41] havenwood: this_dude: So what should your if/else condition be to express that?
[20:59:49] this_dude: dude i ran it again and now i dont get the error
[20:59:56] this_dude: this website is broken af
[21:00:08] this_dude: oo oo pop quiz
[21:00:13] this_dude: gimme a sec
[21:00:45] havenwood: this_dude: That's a reason stuff like https://exercism.io/ is great - you run the tests locally.
[21:00:55] this_dude: what i have no?
[21:00:56] this_dude: if a < b (a..b).sum elsif b < a (b..a).sum
[21:01:14] havenwood: this_dude: "all other cases" is just: else
[21:01:38] this_dude: if a < b (a..b).sum else (b..a).sum
[21:01:49] havenwood: this_dude: To clarify, you want to do `(b..a).sum` when b is smaller, and otherwise, for all cases, do `(a..b).sum`?
[21:02:01] apeiros: alternatively <=, but just else is better.
[21:03:33] this_dude: and i guess this is how you do it in one line
[21:03:34] this_dude: return a < b ? (a..b).reduce(:+) : (b..a).reduce(:+)
[21:03:51] this_dude: no idea what that means though
[21:04:50] havenwood: this_dude: that was the days before #sum
[21:04:53] Creatornator: has joined #ruby
[21:05:10] this_dude: ooo this next problem is interesting
[21:05:21] this_dude: In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.
[21:05:22] havenwood: this_dude: b < a ? (b..a).sum : (a..b).sum
[21:05:33] apeiros: reduce, aka inject will "inject" the operator between every element, i.e. [1,2,3].inject(:+) "becomes" 1 + 2 + 3
[21:05:34] havenwood: this_dude: that is called a "ternary" operator
[21:05:58] havenwood: this_dude: CONDITION ? IF_TRUTHY : IF_FALSEY
[21:06:06] cthulchu_: folks, what does it do? https://paste.ofcode.org/kpRT7utdkZsHrFusCTRvjZ
[21:06:09] cthulchu_: how does it work
[21:06:28] havenwood: this_dude: It's probably better for you to write it: if b < a; (b..a).sum; else; (a..b).sum; end
[21:06:29] cthulchu_: the all_possible_values is just a hash that has all these fields set
[21:07:51] apeiros: cthulchu_: it's an array literal? not sure what part about it you're having trouble with…
[21:08:24] cthulchu_: it creates all combos of that hashes fields vals...
[21:08:38] apeiros: not the code you pasted, no.
[21:08:41] havenwood: cthulchu_: You've showed us a Hash literal. That's all.
[21:08:49] cthulchu_: oh, ok, will continue looking for it
[21:08:50] apeiros: havenwood: array literal. please :-p
[21:09:00] apeiros: (containing hash literals, sure)
[21:09:11] havenwood: apeiros: :-O, Staring at a Hash, trying to write Array. Haha, oops.
[21:09:39] this_dude: is there a way to like... .filter(class:string)
[21:09:41] havenwood: An Array of two mystery Objects, and at least 10 Hashes.
[21:09:44] this_dude: or something like that
[21:10:18] havenwood: this_dude: We use #select for filtering. It gets a #filter alias in 2.6.
[21:10:19] havenwood: this_dude: Or there's a #grep.
[21:10:39] cthulchu_: also what's each_with_index?
[21:10:49] havenwood: this_dude: ['hi there', :no_not_gsub, 42, 'just strings'].grep String
[21:10:50] cthulchu_: I mean, is there anything in an array that wouldn't have an index?
[21:10:55] havenwood: this_dude: #=> ["hi there", "just strings"]
[21:11:05] havenwood: cthulchu_: Everything in an Array has an index.
[21:11:19] cthulchu_: so then what's the point of doing each_with_index to an array?
[21:11:28] cthulchu_: it would do just the same as .each?
[21:11:41] havenwood: chamunks: [:a, :b, :c].each_with_index.to_h #=> {:a=>0, :b=>1, :c=>2}
[21:11:46] havenwood: cthulchu_: ^
[21:11:59] apeiros: the index is implicit
[21:12:04] apeiros: each does not yield the index
[21:12:09] apeiros: only the element
[21:12:18] havenwood: cthulchu_: Check it in IRB or Pry: [:a, :b, :c].each_with_index.to_a
[21:12:21] this_dude: whats the difference between .grep and .gsub
[21:12:21] cthulchu_: it's just to get the index variable inside the block
[21:12:23] cthulchu_: makes sense
[21:12:36] this_dude: get replace and get substitute
[21:12:45] this_dude: i thought its the same thing lol
[21:12:48] gheegh: has joined #ruby
[21:15:15] JJonah: any suggestions for hosting private gems? (either SaaS or something i'd run on my own server). I want something easy, with good discoverability (ability to search gems by keyword).
[21:15:19] this_dude: google isnt helping
[21:18:51] jcarl43: has joined #ruby
[21:20:43] havenwood: JJonah: Do you want to run your own gem server then?: https://guides.rubygems.org/run-your-own-gem-server/
[21:22:18] y3n: has joined #ruby
[21:22:21] JJonah: havenwood: Is geminabox still well maintained? "Latest commit bf71f9b on Jun 15"
[21:23:15] CJKinni: has joined #ruby
[21:23:17] JJonah: Also, does it come with any kind of built in search?
[21:24:06] apeiros: we use geminabox at work. runs fine.
[21:24:24] havenwood: JJonah: it works and everything
[21:24:49] this_dude: ok so apparently .replace doesnt work the way i thought it does
[21:25:27] this_dude: https://dpaste.de/2hUZ
[21:25:39] this_dude: what would i put instead of .replace
[21:26:06] this_dude: i want every character other than the last 4 of any string to replaced with "#"
[21:27:44] this_dude: forgot to actually store the replace value
[21:27:44] this_dude: cc[i]=cc[i].replace('#')
[21:28:24] this_dude: im learning guys! i almost feel ready for my last attempt at the exam haha
[21:30:39] Creatornator: has joined #ruby
[21:30:48] apeiros: replace replaces the complete object
[21:30:59] apeiros: gsub and String#[]= are suitable here
[21:31:24] this_dude: no idea how to use thsoe
[21:31:24] apeiros: for similar cases (IMO not this one, though), tr and delete can also be a choice
[21:31:28] JJonah: this_dude: try something like this instead and avoid loops: http://dpaste.com/07NJ4WP
[21:31:56] apeiros: be wary of edge-cases JJonah ;-)
[21:32:09] this_dude: i have no idea what that code is even doing lmaooo
[21:32:54] apeiros: but String#[] & + is indeed the better choice than via #[]=
[21:33:16] JJonah: this_dude: it's Xing out every char but the last 4
[21:33:32] JJonah: apeiros: which edge case are you thinking?
[21:33:34] this_dude: well i figured but
[21:33:38] apeiros: JJonah: short string
[21:33:39] this_dude: i cant follow the syntax lol
[21:34:14] JJonah: apeiros: if it's a cc number though, should be fine
[21:35:05] apeiros: never trust user input :) but yes, if you know the value has been validated beforehand, you can skip code to handle edge cases.
[21:35:27] JJonah: apeiros: yeah, i was assuming that was the case
[21:35:47] apeiros: I assume the opposite unless expressly being told :)
[21:36:38] apeiros: though, of course, even then you have to know what you want your code to do. if you want it to raise, your method is still fine.
[21:36:49] JJonah: apeiros: i suppose it depends on context. but if this were production code i'd want to see the method that does what i did split out from the validation one way or another.
[21:37:28] this_dude: y'all are way above my level and its so entertaining to read lmao
[21:37:37] CJKinni: has joined #ruby
[21:37:59] this_dude: explain to me please how this works
[21:38:01] this_dude: cc.gsub(/.(?=....)/, '#')
[21:38:11] JJonah: this_dude: try breaking down the different pieces. it's fairly standard ruby. we're just repeating an X for "4 less than as long as the string is". Then I'm using [] to chop off the last 4 chars of the string.
[21:38:13] this_dude: i still dont understand hashes or whatever this is
[21:38:45] apeiros: this_dude: what do you know about regexes so far?
[21:39:04] this_dude: that wasnt in the course material
[21:39:14] this_dude: and its all very confusing
[21:39:16] JJonah: ooohh that regex solution is nice. that's better than mine.
[21:39:36] apeiros: ok, then the high-level explanation: gsub(/.(?=....)/, "#") replaces every character which is followed by any 4 characters with a #
[21:40:11] patr0clus: has joined #ruby
[21:40:28] apeiros: JJonah: dunno, I like yours more tbh.
[21:40:55] gheegh: has joined #ruby
[21:41:30] apeiros: this_dude: basically, gsub will go from left to right through your string, trying to match the regex as often as it can, and replace the matched substring with the second argument ('#' in your case)
[21:41:54] apeiros: and // is the delimiter for the regex (like "" is for strings)
[21:42:07] apeiros: within the regex, . means "any character"
[21:42:35] JJonah: and since the final 4 characters don't have "4 more characters to their right" they don't match, and hence they don't get changed.
[21:42:35] plutes: has joined #ruby
[21:42:38] apeiros: and (?=…) means "followed by …" (the term is "positive look-ahead")
[21:43:01] this_dude: so complicated
[21:43:04] apeiros: so (?=....) is "followed by 4 characters"
[21:43:06] this_dude: im kinda following
[21:43:33] apeiros: but a (?=) group is itself not part of the match, hence it's not replaced, only the first .
[21:43:35] this_dude: (?={4}) == (?=....)
[21:44:09] apeiros: you still need to quantify something :)
[21:44:20] this_dude: i dont quite follow
[21:44:24] apeiros: {4} means "4 of the atom to the left", but you have nothing to the left of it :)
[21:44:34] apeiros: .{4} means "4 of ."
[21:44:48] apeiros: a{4} means "4 of 'a'"
[21:45:13] this_dude: theyre teaching me regexes
[21:45:23] baweaver: Pandoras box has opened
[21:45:37] apeiros: run while you can 😄
[21:45:40] this_dude: knowing you, you probably have an illustrated course on it dnot you
[21:45:57] apeiros: there certainly is a regex lemur
[21:46:10] this_dude: ahahahhahahahaha
[21:46:15] this_dude: you so would lmaooo
[21:46:22] this_dude: i admire that though
[21:46:24] this_dude: dont get me wrong
[21:46:29] baweaver: https://baweaver.gitbooks.io/an-illustrated-guide-to-ruby/content/tyrannosaurus-regexp.html
[21:46:33] this_dude: i wish i had the understanding of the language yall do
[21:46:42] apeiros: needs two wands, though, so they can form the // :D
[21:46:44] baweaver: It's not done
[21:46:48] baweaver: or really all that fleshed out.
[21:47:03] apeiros: baweaver, you're a treasure :D
[21:47:09] this_dude: so this is actually my first programming language not including Robot-C in case yall couldnt tell
[21:47:14] this_dude: what else do y'all code in?
[21:47:21] apeiros: this_dude: you're doing fine
[21:47:23] baweaver: Mind that I stopped updating that version. You'll all see why later.
[21:47:33] this_dude: "<apeiros> baweaver, you're a treasure :D" agreed
[21:48:02] apeiros: this_dude: almost exclusively ruby & js. I do know a couple of other languages. not nearly as fluent in those, tho
[21:48:36] baweaver: Ruby, Javascript, Scala, Haskell*, F#*, Python, Go*, Rust* (*but not strongly)
[21:48:39] this_dude: as soon as i become "proficient enough"in ruby im jumping straight back into python
[21:48:52] this_dude: i tried once before and just couldnt wrap my head round it
[21:49:12] baweaver: Eh, I just don't like the feel of Python
[21:49:34] this_dude: python and objective C are used for sooooo many things now
[21:49:50] this_dude: and violent python is my dream to be able to put into practice
[21:50:10] baweaver: With any luck the lemurs will be at RubyConf this year.
[21:50:22] this_dude: a rubycon?!
[21:50:27] cthulchu_: I have a quick stupid question, folks. How do I add an explicit key-val to a hash? like hashA,push({a:123})
[21:50:34] baweaver: Several. I spoke at Southeast Ruby
[21:50:50] this_dude: pretty sure its not a stupid question since idek what that means lol..
[21:50:56] cthulchu_: just hashA[a]=123?
[21:50:57] baweaver: cthulchu_: what have you tried?
[21:51:08] baweaver: you want a colon before it, but yes.
[21:51:17] cthulchu_: a colon where?
[21:51:25] CJKinni: has joined #ruby
[21:51:43] baweaver: before the a
[21:51:51] baweaver: hash[:a] = value
[21:52:00] cthulchu_: ok, interesting, thanks
[21:52:12] cthulchu_: would hash.a = value work?
[21:52:21] baweaver: not Javascript.
[21:52:29] cthulchu_: what about hash:a?
[21:52:30] apeiros: there's also Hash#store
[21:52:35] apeiros: but nobody uses that :D
[21:52:50] cthulchu_: should we use hash store?
[21:52:54] baweaver: Southeast Ruby: https://2018.southeastruby.com/
[21:52:59] baweaver: No, not really
[21:52:59] apeiros: there's no reason to, no
[21:53:05] cthulchu_: ok, cool, thanks
[21:53:12] apeiros: it's an alias and []= reads nicer.
[21:53:17] cthulchu_: but I guess that method gets called implicitly
[21:54:33] baweaver: Now are there ways to _make_ ruby do those things? Sure, but don't do it.
[21:54:38] baweaver: It's slow and prone to errors.
[21:57:03] apeiros: cthulchu_: re hash.a = value, take a look at OpenStruct
[21:57:24] this_dude: You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
[21:57:24] apeiros: but baweaver's slow & prone comment is of course on-point :)
[21:57:32] baweaver: Hehe, OpenStruct kills method cache too
[21:57:35] apeiros: I even try to avoid hashes if I can and use Struct instead
[21:57:37] mroutis: has joined #ruby
[21:57:39] this_dude: im trying to think how you would do this mathematically
[21:57:49] apeiros: baweaver: is that still an issue? I somehow thought that was resolved?
[21:57:57] apeiros: baweaver: along with extend
[21:58:04] this_dude: string[string.length/2]
[21:58:06] baweaver: havenwood: ^
[21:58:29] gheegh: has joined #ruby
[22:01:57] this_dude: oooo yes "string[string.length/2]" is a valid statement
[22:01:59] this_dude: works in irb
[22:05:08] baweaver: >> def whittle(str) str = str[1..-2] until str.size < 3; str end; [whittle('bob'), whittle('sees'), whittle('things')]
[22:05:09] ruby[bot]: baweaver: # => ["o", "ee", "in"] (https://eval.in/1046627)
[22:06:20] cthulchu_: so I can do something like field_test_combinations[index][:index]=index
[22:06:30] cthulchu_: given that the array is a collection of hashes
[22:06:40] cthulchu_: I just want to put hash index into the hash
[22:07:15] Paraxial: has joined #ruby
[22:07:52] cthulchu_: actually that :index should be a string since it's a key
[22:08:00] cthulchu_: so it should be field_test_combinations[index][:"index"]=index
[22:09:18] duderonomy: has joined #ruby
[22:12:03] apeiros: cthulchu_: ruby has a hash-key equality protocol, which allows you to use virtually any object as a key, not just strings.
[22:12:11] apeiros: I really miss that in JS' Map :(
[22:12:38] cthulchu_: never needed anything more than a string as a key
[22:13:52] alex``: has joined #ruby
[22:15:34] this_dude: @baweaver i did it like this https://dpaste.de/GOKk
[22:17:12] this_dude: wow i couldve just..
[22:17:13] this_dude: s[(s.size-1)/2..s.size/2]
[22:18:53] this_dude: hey what was the method to remove spaces again?
[22:19:26] apeiros: that's from the head & tail. .delete if from anywhere in the string.
[22:23:03] cthulchu_: a=b?b=a:false
[22:23:10] cthulchu_: is that how you end the ternary?
[22:23:24] cthulchu_: or just :nil
[22:24:17] this_dude: shoot im lost
[22:24:40] this_dude: if im given a string like this "1 2 3 4 5" how do i delete the spaces and then put the numbers in an array
[22:24:50] thy0: has joined #ruby
[22:24:57] this_dude: string.to_a.delete(" ")
[22:25:23] apeiros: this_dude: don't delete the spaces.
[22:25:28] apeiros: take a look at String#split
[22:25:42] this_dude: i forgot about split
[22:26:33] this_dude: string.split(" ")
[22:26:39] this_dude: i forgot the basics lmao
[22:26:59] ur5us: has joined #ruby
[22:28:53] this_dude: when i do that
[22:29:02] this_dude: its storing the numbers as string values right?
[22:29:05] this_dude: i need them as integers
[22:29:37] this_dude: cause for some reason if i do string=string.split(" "); return string.max + " " + string.min
[22:29:43] this_dude: i dont get the correct response
[22:31:23] apeiros: probably because "10" < "2", while 10 > 2 :)
[22:31:49] this_dude: ok so how do i change that
[22:31:51] apeiros: check string's docs, I'm sure you'll find a way to convert a string to integer
[22:32:11] this_dude: well obv .to_i
[22:32:18] this_dude: but where do i put that
[22:32:22] this_dude: before .split? or after
[22:33:13] apeiros: which would make more sense?
[22:33:33] this_dude: numbers.split(" ")
[22:33:43] this_dude: oops hit enter too early
[22:34:11] this_dude: numbers=numbers.split(" "); numbers=numbers.to_i
[22:35:46] this_dude: that doesnt do anything :(
[22:36:16] apeiros: well, numbers.split returns an array
[22:36:30] apeiros: you can't call to_i on an array. but the elements in the array are strings.
[22:36:36] alfiemax: has joined #ruby
[22:37:27] cthulchu_: byebug is so extremely useful!
[22:37:31] cthulchu_: I made a wrapper for it
[22:37:34] AJA4350: has joined #ruby
[22:37:52] this_dude: numbers.map { |n| n.to_i }
[22:38:33] apeiros: 👍🏻👏🏻
[22:38:45] this_dude: im on pc..cant see those characters
[22:38:50] this_dude: are those emojis
[22:39:32] this_dude: did i get the answer right or no?
[22:40:37] apeiros: this_dude: thumbs-up + clap
[22:41:07] this_dude: im learning
[22:41:08] apeiros: and shouldn't pc's be able to display emojis too?
[22:41:18] this_dude: my pc is from like.. 2008 XD
[22:41:26] this_dude: it originally ran on vista
[22:42:02] apeiros: ok, not adept with windows. but my wife's macbook from 2010 can display emoji with no problems :D
[22:42:07] this_dude: "string cant be coerced into integer"
[22:42:22] apeiros: you get that when you do something like 1 + "2"
[22:43:07] apeiros: ruby does perform type coercion, but not across certain boundaries. e.g. 1 + 2.0 (integer + float) will work. but 1 + "2" (integer + string) will not
[22:43:08] this_dude: oh wait you're right
[22:43:23] apeiros: of course. I'm always. Even when I'm not. :D
[22:43:25] this_dude: forgot .to_s
[22:43:54] baweaver: >> '1 2 3 4 5'.split.map(&:to_i).sum
[22:44:00] ruby[bot]: baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[22:44:41] this_dude: done https://dpaste.de/PvTi
[22:45:05] nowhereman_: has joined #ruby
[22:45:13] apeiros: this_dude: two stylistic things:
[22:45:17] apeiros: 1) you can scrap the return
[22:45:39] apeiros: 2) we usually prefer "#{numbers.max} #{numbers.min}" over numbers.max.to_s + " " + numbers.min.to_s
[22:45:52] apeiros: note that #{} will call to_s on any non-string value.
[22:46:02] this_dude: didnt know that
[22:46:24] apeiros: hence "1 + 2 = #{1+2)" is fine
[22:46:34] apeiros: apart for the ) vs. } mishap, of course
[22:46:54] this_dude: so i could do
[22:47:05] this_dude: #{numbers.max+numbers.min}
[22:47:21] beowuff: has joined #ruby
[22:47:22] this_dude: oh wait no cause i need the space
[22:47:24] baweaver: apeiros: tsk tsk tsk
[22:47:51] this_dude: ahh! the lady calls..gotta go folks..bbl! tysm for the new knowledge and continued help
[22:47:55] apeiros: baweaver: whatwhatwhat?
[22:47:58] baweaver: https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-minmax
[22:48:29] this_dude: numbers.split.map(&:to_i).minmax.reverse.join(' ')
[22:48:35] this_dude: he means this apeiros
[22:48:53] apeiros: bye this_dude
[22:49:14] baweaver: map isn't necessary there :D
[22:49:31] baweaver: >> '1 2 3 4 5'.split.minmax(&:to_i).reverse.join(' ')
[22:49:33] ruby[bot]: baweaver: # => no implicit conversion of String into Integer (TypeError) ...check link for more (https://eval.in/1046629)
[22:49:40] baweaver: >> '1 2 3 4 5'.split.minmax_by(&:to_i).reverse.join(' ')
[22:49:41] ruby[bot]: baweaver: # => "5 1" (https://eval.in/1046630)
[22:55:57] za1b1tsu: has joined #ruby
[23:07:11] Puffball: has joined #ruby
[23:13:35] arooni: so i have a server that runs an old rails app via nginx + passenger; on ubuntu 16.04 and ruby is setup with rvm. that works fine; but is there a way using rvm / perhaps something else without changing anything that would let me run a separate version of ruby for that app but use a different version elsewhere
[23:15:08] chongtxtx: has joined #ruby
[23:15:13] baweaver: .ruby-version iirc.
[23:15:35] dviola: has joined #ruby
[23:17:10] apeiros: arooni: passenger can run multiple ruby versions at the same time, yes
[23:17:39] Pisuke: has joined #ruby
[23:17:44] apeiros: just configure the ruby version per virtual host
[23:18:54] arooni: oh wow; didnt know i could do that;
[23:19:02] arooni: been awhile since i looked at this app lol
[23:19:27] arooni: so if i set a default in my shell (fish) that wont affect the app?
[23:21:39] apeiros: probably depends on your passenger config. but I think even in the standard config it shouldn't matter if you change your shell's ruby version.
[23:26:33] alfiemax: has joined #ruby
[23:32:57] postmodern: has joined #ruby
[23:34:37] baweaver: >> $_=(@_=[*?`..?{][(_=$$/$$)..-_-_]*'')=~/$/;(@__=->_,___,__=''{__<<@_[(___+(@_=~/#{_[$.]}/))%$_];_[$.+=$_/$_]?@__[_,___,__]:__})['ganjah', 4]
[23:34:42] ruby[bot]: baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[23:42:28] beowuff: has joined #ruby
[23:49:13] nicesignal: has joined #ruby
[23:54:13] DarthGandalf: has joined #ruby