baweaver changed the topic of #ruby to: Rules & more: https://ruby-community.com | Ruby 2.5.1, 2.4.4, 2.3.7, 2.6.0-preview2: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.de/ and select ruby as the language | Rails questions? Ask in #RubyOnRails | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | Can't talk? Register/identify with Nickserv first!
<this_dude> ofc not
<baweaver> I'd said it two times above: str.chars.rotate ....
<baweaver> you missed that twice.
<this_dude> ok but idk how to write that out
SeepingN has quit [Quit: The system is going down for reboot NOW!]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood> 'this_dude'.chars.rotate
<this_dude> s.chars.rotate(leftShift).rotate(rightShift)
<this_dude> ??
<havenwood> this_dude: We don't use headlessCamelCase ever in Ruby.
<baweaver> Remember rotate defaults to right
<baweaver> so you get two right rotates like that
<havenwood> this_dude: left_shift and right_shift in snake_case
<baweaver> but the syntax is correct.
<this_dude> so then it would be
<baweaver> one needs to be negative.
<this_dude> s.chars.rotate(rightShifts - leftShifts)
<baweaver> that too
<this_dude> ugh
<baweaver> I'd just threw a negative on a second rotate
<this_dude> i got it super wrong then
<galaxie> Hmm, can I sort/prioritize RuboCop warnings? Like, choose which ones pop up first in, say, Vim Syntastic?
<baweaver> >> def get_shifted_string(str, right, left) str.chars.rotate(right).rotate(-left).join end; get_shifted_string('foobar', 3, 5)
<ruby[bot]> baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<mroutis> sure, galaxie
<galaxie> I believe Syntastic has some ability to do that, but I was wondering if RuboCop itself had the ability.
<mroutis> you can specify them in a .rubocop.yml
<mroutis> read the first paragraph, galaxie, https://rubocop.readthedocs.io/en/latest/configuration/
<galaxie> mroutis: Well, yes, I can disable cops, but if I really couldn't care less about line length compared to, say, security warnings..
<mroutis> oh, right, I misread that, sorry
<galaxie> mroutis: Oh wait, is it severity I'm looking for?
<mroutis> yep, galaxie
chouhoulis has joined #ruby
ansraliant has joined #ruby
<this_dude> wow
<this_dude> i got the answer
<this_dude> way too late ofc
<this_dude> if we had that conversation earlier i wouldve passed..
<this_dude> s.chars.rotate(rightShifts).rotate(-leftShifts).join
<this_dude> smh
<mroutis> and you can filter the severity when calling `rubocop`
<this_dude> I have one last try
<havenwood> this_dude: s.chars.rotate(right_shifts - left_shifts).join
<this_dude> that works too
<this_dude> i wish y'all wouldve told me that earlier
<this_dude> you were being kinda creul tbh..
noobineer has quit [Ping timeout: 256 seconds]
<this_dude> cruel*
<this_dude> like ok i get it..self study is the best way to learn
<havenwood> this_dude: Your timing is just off.
<mroutis> using something like `rubocop --fail-level falat`, galaxie
<this_dude> my timing?
<havenwood> this_dude: You decided to learn *during* the test. We'd have been happy to help back when we could have.
<this_dude> because i have no idea what kinda problems theyre gonna throw at me
<this_dude> and .rotate and all that werent in the resources they provided me to study
<baweaver> codewars.com
<this_dude> i studied and memorized everything they provided me with
<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
<mroutis> this_dude, you can achieve the same thing without `.rotate`
<this_dude> how so
mikecmpbll has quit [Quit: inabit. zz.]
cagomez has quit [Remote host closed the connection]
<galaxie> mroutis: Minimum severity (A/R/C/W/E/F) for exit ... what's A stand for? R is Refactor..
<galaxie> mroutis: Allowed?!
<mroutis> A is autocorrect, I guess, galaxie
cagomez has joined #ruby
<this_dude> should i just jump into my last try and i fail just give up on being a coder ..
<this_dude> cause im limited on time
<this_dude> i only have 2 days left to take the last attempt
<this_dude> and idk what else i can possibly study
<mroutis> well, prepare
<baweaver> Go through a bunch of problems on codewars.com
<this_dude> kk
<mroutis> this ^
<baweaver> spend a solid day on it.
<baweaver> or two even
<mroutis> both
<al2o3-cr> this_dude: possibly the language
<baweaver> that's what I tend to do to remember stupid little things.
<this_dude> okay let me see whats up
<blood> Is there no way to remove a parent element after matching a specific element by value using REXML?
<mroutis> blood, do you have an example?
<blood> yes one moment
jcarl43 has quit [Read error: Connection reset by peer]
jcarl has joined #ruby
<this_dude> im trying this coding wars thing
<this_dude> its kinda cool actually
<this_dude> really helpful so far
<al2o3-cr> this_dude: what katas?
<this_dude> what lol
<mroutis> lol, it've been 5 minutes, "really helpful so far"
<this_dude> dude ive gone through like 5 problems already
<this_dude> its super cool
<this_dude> and the thing is when im not on a time constraint i can think so much clearer
<this_dude> it sucks
<this_dude> im terrible under timed pressure
<mroutis> life is time constrained, this_dude
cagomez_ has joined #ruby
cagomez has quit [Ping timeout: 248 seconds]
<this_dude> why are you guys all so cryptic ahaha
<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
<havenwood> ?guys this_dude
<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?
<this_dude> i feel like y'all shouldve been philosophy majors
<havenwood> this_dude: I was a philosophy major.
<this_dude> i forgot havenwoods name is sarah
<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
<this_dude> MAKES SENSE
<havenwood> this_dude: my name is shannon
<this_dude> yeah that...i apologize
<blood> I tried to review the ruby docs but couldn't find anything on how to remove a parent element
<galaxie> mroutis: Also, it's still sorting by line number, not severity
<this_dude> ooo heres something idk
<this_dude> how do you return a sum in ruby in terms of binary
<mroutis> galaxie, can't tell, sorry :/
<al2o3-cr> this_dude: how'd you mean?
<galaxie> mroutis: Any experience with Syntastic/Vim?
goez has joined #ruby
chouhoulis has quit [Read error: Connection reset by peer]
cagomez_ has quit [Ping timeout: 248 seconds]
<this_dude> like
<this_dude> i want to add two integers and return their sum in binary
<this_dude> for example
<mroutis> no, galaxie, I use vim but not syntastic
<this_dude> sum = a + b
<this_dude> but..
<this_dude> i want sum in binary
<mroutis> you could try debugging by running rubocop outside of vim, without syntastic
<al2o3-cr> >> 255.to_s(2)
<ruby[bot]> al2o3-cr: # => "11111111" (https://eval.in/1046164)
<havenwood> this_dude: my little code dojo in Topanga was the original code wars dojo ;-)
<galaxie> mroutis: What do you use, then?
<this_dude> .to_s(2)
<this_dude> whats that do
<this_dude> isnt .to_s converstion of an array to a string
<this_dude> conversion*
<havenwood> this_dude: It's explicit conversion from anything to a String.
<havenwood> this_dude: (Not Array.)
<this_dude> oh
<this_dude> well
<havenwood> [].to_s #=> "[]"
<this_dude> how does that return binary
<mroutis> when I'm about to open a PR, I run rubocop to tests for style issues, galaxie
<blood> mroutis: if you need more information let me know =) Thanks!
<this_dude> is the 2 a definition of the string in terms of base 2?
Creatornator has joined #ruby
<al2o3-cr> this_dude: representation
<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?
<havenwood> this_dude: 42.method(:to_s).owner #=> Integer
<this_dude> o-o
<this_dude> what
<al2o3-cr> >> 255.to_s(16) # hex
<ruby[bot]> al2o3-cr: # => "ff" (https://eval.in/1046165)
<blood> Basically, I need to modify/remove/add XML
<havenwood> "Returns a string containing the representation of int radix base (between 2 and 36)."
<blood> I have no issues with modify/add , only remove
<this_dude> >> 2.to_s(2)
<ruby[bot]> this_dude: # => "10" (https://eval.in/1046166)
<this_dude> WOW
<havenwood> this_dude: Yeah, binary.
<this_dude> THATS SO COOL
<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)
<havenwood> this_dude: "10".to_i(2) #=> 2
<blood> I'm trying to match an element based on a value and have it remove all elements including children up to root
<havenwood> this_dude: Or strict conversion: Integer("10", 2) #=> 2
<this_dude> wait
<this_dude> so i can take an integer string value and turn it into an integer in terms of other bases
jdawgaz has quit [Ping timeout: 256 seconds]
<this_dude> so i can go back and forth
<this_dude> thats SO COOL
<mroutis> mhm, blood, why don't you find the parent before deleting the element and call `delete_all(parent_path)`
<mroutis> I'm just trying to figure out what's going on, sorry if I can't help that much
<this_dude> how do i go to the next question on this thing havenwood
<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
<blood> If I can do that then sure let me know =)
<havenwood> this_dude: I don't know the question. Are you allowed direct assistance?
<blood> I assume I should just check children on each element as I traverse then delete if it contains my criteria
<mroutis> I think that could work, blood ^
<this_dude> i meant after i finish one correctly
<this_dude> theres no next button haha
<al2o3-cr> this_dude: quick little test for you, you up for it?
<this_dude> sure!
<this_dude> always
<blood> If this were java, i would be done already but just starting to work with ruby =)
<al2o3-cr> this_dude: convert "#ff0000" into rgb constituent parts
<this_dude> whats that
<this_dude> rgb constituent parts
<mroutis> I've never used REXML, always Nokogiri <3
goez has quit [Ping timeout: 240 seconds]
<al2o3-cr> this_dude: so return an array with 3 integers
<this_dude> isnt #ff0000 a color code lol
<al2o3-cr> this_dude: yep
<this_dude> nice
cthulchu_ has quit [Ping timeout: 256 seconds]
<this_dude> anyways ok i got this
<this_dude> gimme a sec
<blood> mroutis: better? I'm only using REXML since it was used for this puppet module
<al2o3-cr> this_dude: ok
<this_dude> can i assume thats in hexidecimal since its a color code
<al2o3-cr> it is
<this_dude> kk
<mroutis> can't compare, since I haven't use REXML :p
<this_dude> >> "ff0000".to_i(16).to_a
<ruby[bot]> this_dude: # => undefined method `to_a' for 16711680:Fixnum ...check link for more (https://eval.in/1046167)
<this_dude> shoot
<this_dude> hmm
thejs has joined #ruby
<blood> http://www.rubyinside.com/ruby-xml-performance-benchmarks-1641.html According to this, REXML is painfully slow
<blood> i should give nokogiri a shot
<this_dude> "ff0000".to_i(16).split.to_a
<this_dude> >> "ff0000".to_i(16).split.to_a
<ruby[bot]> this_dude: # => undefined method `split' for 16711680:Fixnum (NoMethodError) ...check link for more (https://eval.in/1046168)
<this_dude> agh
<havenwood> this_dude: try in your own irb first
jcarl has quit [Quit: WeeChat 2.2]
<this_dude> ok srry
<this_dude> when using irb in command line
postmodern has joined #ruby
<this_dude> if i wanna use it for ruby do i execute ruby irb
<this_dude> or still just irb
<havenwood> this_dude: from the command line, just: irb
<this_dude> kk
<this_dude> so uh
<this_dude> you said you want a result of an array with 2 numbers
<havenwood> this_dude: 3
<this_dude> but thats translates to 16711680
<this_dude> yeah 3 srry
<this_dude> so i dont understand what you want exactly
<havenwood> this_dude: [255, 0, 0]
<al2o3-cr> this_dude: for a clue use String#scan(rexexp) Enumerable#map String#hex
<havenwood> this_dude: What's base ten number does "FF" represent in hex?
<this_dude> 16
<havenwood> >> "FF".hex
<ruby[bot]> havenwood: # => 255 (https://eval.in/1046169)
<this_dude> oh wtf
<this_dude> how
<this_dude> >> 16*16
<havenwood> this_dude: What's "A" in hex?
<ruby[bot]> this_dude: # => 256 (https://eval.in/1046170)
<this_dude> 11
<havenwood> this_dude: right
<havenwood> this_dude: And "AA" is?
<this_dude> 121?
<havenwood> this_dude: (Try in IRB.)
<this_dude> >> "AA".hex
<ruby[bot]> this_dude: # => 170 (https://eval.in/1046171)
<this_dude> HOW
<havenwood> this_dude: 1, 2, 3, ..., 9, 10, A, B, ... E, F, then ???? what's next?
<this_dude> 1?
<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")'
<havenwood> this_dude: 10
<this_dude> o-o
<havenwood> this_dude: like what's after 9 in base 10?
<this_dude> 0
<havenwood> this_dude: nope, 10
<havenwood> 8, 9, and ... 10!
<this_dude> wtf
mroutis has left #ruby [#ruby]
<this_dude> but base 10 is 0-9
<havenwood> this_dude: right, and in base 10 (normal counting), what's after 9?
<this_dude> oh
<this_dude> true
<this_dude> so then
<this_dude> in base 16
MuffinPimp has quit [Quit: Goodbye.]
<this_dude> how does 10 come after F
<havenwood> this_dude: in normal counting, you exhaust the set, then put a 1 in front, right? same rule.
<havenwood> this_dude: E, F, 10, 11
<this_dude> <havenwood> this_dude: 1, 2, 3, ..., 9, 10, A, B, ... E, F, then ???? what's next?
<havenwood> this_dude: 10
<this_dude> why did you put a 10 after 9 then
<havenwood> this_dude: i fail
<havenwood> multitasking on a base 10 brain
<this_dude> oh...so its ...9,a,b,c..etc
<this_dude> ?
<havenwood> this_dude: yeah, sorry for the confusion
<this_dude> ohhhhhh ok
<havenwood> this_dude: like binary is: 0, 1, 10
<this_dude> ok makes sense
<this_dude> i got it
<this_dude> so for example
<havenwood> this_dude: So RGB is three numbers from 0-255.
<havenwood> this_dude: Or in hex, three numbers from "00" to "FF"
<havenwood> this_dude: in al2o3-cr's example, "FF", "00" and "00"
<havenwood> this_dude: which is 255, 0 and 0
<havenwood> "FF0000"
<this_dude> they arent all one number?
<havenwood> nope
<this_dude> how can you tell?
galaxie has quit [Quit: ircII EPIC4-2.10.6 -- Are we there yet?]
<havenwood> that's how RGB works
<this_dude> didnt know that
<this_dude> oops
<this_dude> what does RGB stand for
<this_dude> red green blue
<this_dude> im stupid
<this_dude> nvm
<havenwood> this_dude: or rather, the hex #RRGGBB representation is common in RGB
r29v has quit [Quit: r29v]
<havenwood> this_dude: So 100% red and 0% green and blue.
<this_dude> for FF0000?
<havenwood> this_dude: yes
<this_dude> i see
<this_dude> that makes sense
<al2o3-cr> this_dude: i bet you don't remember crt televisions
<this_dude> let me do this problem on code wars hold on
<this_dude> remember what lmaoooo
<this_dude> dude im 21 XD
<al2o3-cr> embrace on the test given
<havenwood> this_dude: but how old is that in hex?
cjkinni has quit [Ping timeout: 260 seconds]
<this_dude> >> 21.to_s(16)
<ruby[bot]> this_dude: # => "15" (https://eval.in/1046172)
<this_dude> loooooool
<this_dude> so question
<this_dude> can you execute an if statement outside of a while loop?
<havenwood> >> 'so what' if 'you can?'
<ruby[bot]> havenwood: # => /tmp/execpad-8a9b5ab462ab/source-8a9b5ab462ab:2: warning: string literal in condition ...check link for more (https://eval.in/1046173)
<havenwood> #=> "so what"
<this_dude> huh
<havenwood> this_dude: Try in irb. Or you might want to just switch to pry right away.
<havenwood> this_dude: gem install pry pry-doc && pry
<al2o3-cr> havenwood: only on string literals not array, hash or any other objects.
<this_dude> for example can i just put if "statement" = "boundary" return true
<this_dude> better example
<this_dude> if x % (x.sqrt) == 0 return true
<this_dude> can i put that
<this_dude> or do i have to specify while x > 0
<havenwood> this_dude: return true if x % x.sqrt == 0
jottr has quit [Ping timeout: 240 seconds]
<havenwood> this_dude: but you'd not need the if, since it's already truthy
<al2o3-cr> yeah just; x % (x.sqrt) == 0
<this_dude> so just x % (x.sqrt) == 0; return true
<havenwood> this_dude: oh, for the early return you mean?
MuffinPimp has joined #ruby
<this_dude> yeah
<this_dude> while x > 0; if x % (x.sqrt) == 0; return true; elsif x % (x.sqrt) != 0; return false
<this_dude> is this written correctly?^
<this_dude> or is there a simpler way to write that
<al2o3-cr> no just; x % (x.sqrt) == 0 # it's either true or false.
<this_dude> so
<this_dude> x % (x.sqrt) == 0; return true; else return false
<this_dude> ?
patr0clus has joined #ruby
<al2o3-cr> >> 5 % 4 == 0
<ruby[bot]> al2o3-cr: # => false (https://eval.in/1046174)
<al2o3-cr> >> 5 % 5 == 0
<ruby[bot]> al2o3-cr: # => true (https://eval.in/1046175)
<this_dude> ohhhh youre saying i dont have to put the "return false/true"
<this_dude> cause itll do it automatically
<al2o3-cr> yeah, dude.
<this_dude> its saying its wrong
<this_dude> hmm
<havenwood> this_dude: I'd write that as either:
<havenwood> 42.modulo(Math.sqrt(42)).zero?
<havenwood> or
<havenwood> 42 % 42 ** 0.5 == 0
<this_dude> the problem is to create a method that tells if a number inputted is a perfect square
<havenwood> assuming x is 42
<al2o3-cr> this_dude: well a perfect sqr is 1*1, 2*2, 3*3 and so forth
<this_dude> so then i could do
<this_dude> yeah ik
<this_dude> hmm
<this_dude> confused how to write thi
<this_dude> this*
<al2o3-cr> this_dude: you're consusing square root with a squared number. use abs2
<this_dude> whats that
<al2o3-cr> *confusing
<this_dude> i guess my mathematical logic for is was that
<this_dude> for it*
<havenwood> this_dude: squaring
<havenwood> this_dude: I work at Square so we deal with this all the time!
<havenwood> >> 42.abs2
<ruby[bot]> havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<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?
<havenwood> #=> 1764
<al2o3-cr> this_dude: gist the test code again
<this_dude> hold on i gotta relocate coffee shop is closed
<this_dude> imma drive home be back in 15/20
this_dude has quit [Quit: Page closed]
moei has quit [Ping timeout: 244 seconds]
this_dude has joined #ruby
<this_dude> im bck lol
<this_dude> i just found on outlet at the park
<this_dude> and connected to my phone hotspot
<this_dude> anyways so
<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
<this_dude> and if the number can be divided by the square root with % and return 0 its true
<this_dude> right?
<this_dude> >> 9 % (9.sqrt) == 0
<ruby[bot]> this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<this_dude> hmm
<this_dude> >> 9 % (9.sqrt) == 0?
<ruby[bot]> this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<this_dude> agh
<havenwood> this_dude: 9.modulo(Math.sqrt(9)).zero? #=> true
<havenwood> this_dude: 9 % 9 ** 0.5 == 0 #=> true
<havenwood> this_dude: That's true.
<this_dude> whats ** 0.5
<this_dude> i dont understand that function
<al2o3-cr> this_dude: this_dude square root
raulp has quit [Ping timeout: 245 seconds]
<al2o3-cr> like n ** (1/3.0) is cube root
<this_dude> OHHHHHH
<this_dude> ** == ^
<al2o3-cr> this_dude: yep
<this_dude> 9 ** .05 == 9 ^ .5
<this_dude> .5*
<this_dude> makes sense okok
<al2o3-cr> yep
<al2o3-cr> ^ in ruby is exclusive OR
<al2o3-cr> this_dude: anyway where's the gist
<this_dude> hmm im doing something wrong
<this_dude> what gist
<al2o3-cr> this_dude: test code
<this_dude> oh for the problem im solving?
<al2o3-cr> aye/
<this_dude> am i expressing x greater than or equal to 0 wrong?
<this_dude> is it => or >=
<al2o3-cr> this_dude: why you using a loop for that?
<al2o3-cr> this_dude: logic starts in the brain you know
<this_dude> should i just use
<this_dude> if x>= 0
<this_dude> ?
<this_dude> instead of while
sylario has quit [Quit: Connection closed for inactivity]
def_jam has joined #ruby
eb0t_ has joined #ruby
<this_dude> hmm its giving me a wrong response for the number 0
<this_dude> how do i overcome the fact that you cant divide by 0
<Radar> hello again friends.
<this_dude> hey radar
<Radar> this_dude: please stop using while loops for things that do not need them.
<this_dude> do i just specify that if x == 0 return true
eblip has quit [Ping timeout: 240 seconds]
<this_dude> ?
goez has joined #ruby
<this_dude> ayy ok):
<Radar> whoever is encouraging you to write Ruby should go... away.
<Radar> well, write Ruby _like this_
<havenwood> >> 0.step.lazy.select { |n| Math.sqrt(n).modulo(1).zero? }.first 10
<ruby[bot]> havenwood: # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] (https://eval.in/1046180)
eb0t has quit [Ping timeout: 240 seconds]
<Radar> Thank you havenwood for showing some neater Ruby code.
<this_dude> oh i fixed it
<this_dude> its cause the code im using is the code i need to use on the exam
<this_dude> i have one try left
<this_dude> i failed again while you were gone
<this_dude> lolol
<Radar> Gone / asleep same thing.
<this_dude> yeah haha
<Radar> Hmmm almost as if you shouldn't be writing Ruby so strangely? 🤔
<this_dude> its what they want idk
<Radar> Are you _certain_?
<this_dude> dont tell me tell them ahaha
<this_dude> yes
<Radar> Where did they say this?
<this_dude> im gonna paste a SS ok?
<this_dude> its not of code
<Radar> ok.
<this_dude> thats where they specified
<this_dude> i was given a list of material to study
<Radar> Oh that again. I remember that.
<this_dude> its supposed to be "all i need to pass the exam"
<Radar> So the two times you failed the exam, did they tell you what you did wrong?
<this_dude> nope
<this_dude> doesnt even say which ones i got wrong
<this_dude> just said
<this_dude> "you failed you have x amount of tries left"
<Radar> Did you test your code and see if it actually returned what it expected?
<this_dude> and i get a new link to retry lol
<this_dude> i ran out of tiem
<this_dude> time
<this_dude> i got one of them
<Radar> So practice now.
<this_dude> the last 2 i got absolutely stuck on
<this_dude> thats what im doing ...someone gave me a link to codewars.com
<Radar> It is not that hard to write tests for code. I will bring up an example.
<this_dude> its helpful
<this_dude> im gonna spend the next day or so on there
<this_dude> and then go back to the exam
<Radar> this_dude: ^
<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.
<Radar> These tests then allow you to refactor your code after you've finished making them all pass.
<Radar> bbl
<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
<this_dude> or array or whatever its asking for
tdy has quit [Ping timeout: 240 seconds]
<baweaver> >> {}.respond_to?(:to_proc)
<ruby[bot]> baweaver: # => true (https://eval.in/1046181)
<baweaver> Radar / al2o3-cr: Oh yes
<al2o3-cr> this_dude: it's as simple as n ** 0.5 % 1 == 0
<this_dude> oh shoot you right
<al2o3-cr> as what havenwood and Radar wrote
<this_dude> my way worked but yours is way shorter
<this_dude> so smart
<this_dude> this is why i idolize y'all
<this_dude> so you realize how much ive learned from this irc chat?
<al2o3-cr> this_dude: you were told this by havenwood
<this_dude> do*
<this_dude> i didnt see it srry
<al2o3-cr> earlier.
<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 }
<ruby[bot]> baweaver: # => 0 (https://eval.in/1046182)
<this_dude> no but i mean the %1
<this_dude> instead of %n
<this_dude> i didnt think of that
<baweaver> Hash#to_proc => -> key { hash[key] }
<this_dude> cause if the square root returns a decimal its automtically not a perfect square
<this_dude> i didnt think to use %1
herbmillerjr has joined #ruby
<al2o3-cr> ok, why use % 1
<baweaver> Much faster than public send
<this_dude> because with %1 if n is 0 then i obviously cant divide by 0
<this_dude> so %1 makes me able to compute 0 as well
<this_dude> and eliminates the extra line of code i added for the 0 case
<al2o3-cr> wow, you are learning fast.
<this_dude> im a fast learner when im given answers and not told to research it myself ahahaha
<this_dude> i absorb information way faster that way
<this_dude> I have a photographic memory so if you just throw a bunch of info at me ill memorizze it
<al2o3-cr> it ensures it an integer.
<al2o3-cr> *it's
<this_dude> instead of a float
<this_dude> yup
<this_dude> anyways on to the next problem
<this_dude> this ones kinda weird but i got it
<al2o3-cr> cool, you're heading in the right direction now
<this_dude> new question
<this_dude> so
<this_dude> if i need to split a string
<this_dude> but i need to split it in two ways...can i do this --> .split("WUB","WUBWUB").join(" ")
<al2o3-cr> tias
<this_dude> so that it will remove any instance of both of those combinations of characters and replace it with " "
<this_dude> what lol
<al2o3-cr> try it and see.
<this_dude> i did and got an error
<this_dude> but idk why
<this_dude> doesnt specify
<al2o3-cr> show your code.
<al2o3-cr> this_dude: what is song and what is expected result?
<this_dude> oh i forgot someting
<this_dude> so the string inputed will be as such
<baweaver> >> ObjectSpace.each_object.select { |o| o.is_a?(Class) && o.instance_methods.include?(:to_proc) rescue false }
<ruby[bot]> baweaver: # => [Method, Proc, Hash, Symbol] (https://eval.in/1046185)
<this_dude> so like the string can be "WUBIWUBHATEWUBWUBMYSELFWUB"
<al2o3-cr> this_dude: i said paste not image.
<this_dude> thats the problem
<this_dude> its super long
<this_dude> so like the string can be "WUBIWUBHATEWUBWUBMYSELFWUB"
<this_dude> and the result needs to be "I HATE MYSELF"
<al2o3-cr> is that the real result?
<this_dude> its the result my code should return
<al2o3-cr> should be
<al2o3-cr> by why insert that?
<this_dude> oh idk it was just a random string off the top of my head ahahaha
<this_dude> so, so far my code works only when theres no "WUB" at the beginning or end of the string
<this_dude> and when there's no "WUBWUB" in the string
<this_dude> i need to be able to specify that if the string starts or ends with "WUB" or "WUBWUB" then just delete it
ciro has quit [Quit: WeeChat 2.2]
<this_dude> and i need to be able to replace "WUBWUB" with " " the same way i did with just "WUB"
shakes has joined #ruby
<this_dude> can you specify multiple split parameters?
<this_dude> such as .split("WUB","WUBWUB")
<this_dude> or would it be .split("WUB").split("WUBWUB")
<this_dude> let me test it
<al2o3-cr> >> "WUBIWUBHATEWUBWUBMYSELFWUB".gsub(/WUB*/, ' ')
<ruby[bot]> al2o3-cr: # => " I HATE MYSELF " (https://eval.in/1046198)
<this_dude> oh but thats wrong
<this_dude> cause its returning a double space where theres a WUBWUB
<this_dude> thats one of the errors i got too
<this_dude> and its also returning a space at the beginning and end of the string
<this_dude> i need that to return "I HATE MYSELF"
<this_dude> thats where i'm stuck atm
<this_dude> wait i think i got it
savolla has quit [Remote host closed the connection]
<al2o3-cr> this_dude: is it a constraint to use while loops?
<this_dude> no
<this_dude> i just figured i needed it
<this_dude> to test each index of string.split
thejs has quit [Ping timeout: 240 seconds]
<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
<this_dude> and that you can have a double space in the string result either
arescorpio has quit [Quit: Leaving.]
<this_dude> and that you CANT have a double space in the string result either**
thy0 has quit [Quit: TTFN]
tdy has joined #ruby
[reed] has quit [Ping timeout: 268 seconds]
<this_dude> oh wait i found an easier way to take care of the double space thing
<this_dude> i think
<this_dude> res = res.split(" ").join(" ")
<this_dude> ?
<this_dude> is this a valid command ahaha
<this_dude> shoot no that didnt work
<this_dude> did everyone go afk :/
<Radar> yes
<Radar> this_dude: This is using a test framework called minitest
<Radar> There are 3 tests here, that test the `is_square` function with the numbers 1, 4, and 5.
tag has quit [Quit: Connection closed for inactivity]
<Radar> This is saying for 1 + 4, the `is_square` method should return `true` (assert). But for 5, it should return false (refute)
<Radar> You can run this test file by saving it to a file and running `ruby thatfile.rb`
<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.
<this_dude> but thats for a problem i already finished
<Radar> Ok, so adapt it to the next problem then.
<this_dude> oh codewars is doing the same thing for me
<this_dude> it has those minitests in it too
<this_dude> and tells me where my result went wrong
<this_dude> my issue is idk how to fix it
<this_dude> okay fine simple question
<this_dude> how can i use .split to split two different parameters
<Radar> this_dude: input + expected output plz
<pabs> this_dude: if you mean split on two different parameters, you can do it like this:
<pabs> >> 'foo,bar:baz'.split(/,|:/)
<pabs> => ["foo", "bar", "baz"]
<ruby[bot]> pabs: # => ["foo", "bar", "baz"] (https://eval.in/1046209)
<al2o3-cr> this_dude: use gsub
<Radar> can we not give answers to a problem we haven't seen yet?
<this_dude> but i showed the problem
<Radar> [12:24:24] <Radar>this_dude: input + expected output plz
<this_dude> ok
<Radar> I don't see a single message from you about that.
<this_dude> so
<al2o3-cr> Radar: i've seen it
<Radar> enter is not a space bar.
<this_dude> can i ss the problem?
<this_dude> srry
shakes has quit [Quit: Leaving]
<Radar> Sure.
<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?
<this_dude> ok heres a ss of the problem and expected input and output
fluxAeon has quit [Quit: Textual IRC Client: www.textualapp.com]
<this_dude> oh okay i know what my issue is now
<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 " "
<this_dude> its raining and im outside gotta relocate brb
fluxAeon has joined #ruby
AJA4350 has quit [Quit: AJA4350]
<Radar> this_dude: Ok, can you work out how to replace all the WUBs with a single space?
<Radar> this_dude: So if I had "AWUBWUBB" That would give me "A<space><space>B"
this_dude has quit [Ping timeout: 252 seconds]
mroutis has joined #ruby
lupine has quit [Ping timeout: 255 seconds]
lupine has joined #ruby
thejs has joined #ruby
maryo_ has joined #ruby
JamJam_kid has joined #ruby
cadillac_ has quit [Quit: I quit]
cadillac_ has joined #ruby
braincrash has quit [Quit: bye bye]
bambanx has quit [Quit: Leaving]
<blood> Is there a better way to handle this https://dpaste.de/Y1J2 ? This runs pretty slow
<blood> But it does work...
<blood> mroutis: I got a method to work but REXML runs extremely slow
<blood> I'll need to convert what I have to nokogiri
this_dude has joined #ruby
braincrash has joined #ruby
<this_dude> back
maryo_ has quit [Ping timeout: 240 seconds]
<al2o3-cr> this_dude: wb
mojtaba has joined #ruby
<this_dude> ty
<this_dude> so back to what i was asking before
<this_dude> this command line --> res = song.split("WUB"||"WUBWUB").join(" ")
<this_dude> is obviously incorrectly written
<this_dude> but i need to be able to remove "WUB" no matter how many times its repeated
<this_dude> i.e. "WUBWUBWUB" or "WUBWUBWUBWUB"
<this_dude> and still replace it with just a single space
<ArahaelPi> this_dude: That reminds me of the story: "Beyond lies the Wub".
<this_dude> lul
<blood> What version of nokogiri supports ruby 2.1.9?
<this_dude> any idea how to do that?
<this_dude> anyone lol
<al2o3-cr> this_dude: i have an idea
<this_dude> inb4 its a sarcastic idea :/
<Radar> [12:36:43] <Radar>this_dude: Ok, can you work out how to replace all the WUBs with a single space?
<Radar> [12:37:19] <Radar>this_dude: So if I had "AWUBWUBB" That would give me "A<space><space>B"
<this_dude> oh i went afk for that..let me load the log hold on
<this_dude> oh so for that one
<this_dude> i could just use song.split("WUBWUB").join(" ")
<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
<this_dude> and the problem states that it can be any random number of times that "WUB" is used
<this_dude> or for [12:37:19] <Radar>this_dude: So if I had "AWUBWUBB" That would give me "A<space><space>B"
<this_dude> it would be song.split("WUB").join(" ") to give "A<space><space>B"
<Radar> >> AWUBWUBBsplit("WUB").join(" ")
<ruby[bot]> Radar: # => undefined method `AWUBWUBBsplit' for main:Object (NoMethodError) ...check link for more (https://eval.in/1046224)
<Radar> >> "AWUBWUBB".split("WUB").join(" ")
<ruby[bot]> Radar: # => "A B" (https://eval.in/1046225)
<Radar> this_dude: right.
<this_dude> so now i need it to only return a single space instead
orbyt_ has joined #ruby
<this_dude> even if its WUB x3,4,5,etc
<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.
<this_dude> oh that is new info ty
<this_dude> have any links?
<baweaver> google.com
<this_dude> yeah im googling it rn ahahah
lupine has quit [Ping timeout: 240 seconds]
<this_dude> wow thats so easy
<this_dude> can i do .squeeze(" ")
<this_dude> to specify what to squeeze?
<this_dude> gonna test it..sorry stupid question
<Radar> he is learning
<Radar> bbl lunch
<this_dude> got it! just once last thing to figure out
<this_dude> i cant have spaces at the beginning or end of the result string
JamJam_kid has quit [Remote host closed the connection]
<this_dude> ok absolutely no idea how to do that
lupine has joined #ruby
<Caerus> as with a lot of things in ruby. very simple ;) it is one of the string methods.
<Caerus> >> " foo bar ".strip
<ruby[bot]> Caerus: # => "foo bar" (https://eval.in/1046228)
<this_dude> wow
<this_dude> ruby never fails to make me feel stupid
<this_dude> i was gonna do this
<this_dude> if res.split[0] == ' '; res.split[0].shift; elsif res.split[res.length] == ' '; res.split[res.length].pop
<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.
<this_dude> is there like...a list of methods lol
<Caerus> chances are, there´s a more idiomatic way
<this_dude> cause i had no idea those were a thing
<Caerus> this_dude, absolutely and you should use it, a lot.
<this_dude> wow
<Caerus> for instance, related to the .strip, it belongs to String class
<this_dude> tysm
<this_dude> thats gonna make my life sooooo much easier
<Caerus> I´m also pretty sure there is a way to check the methos of each class either through irb or pry
<baweaver> >> String.methods.sample(5)
<ruby[bot]> baweaver: # => [:singleton_method, :public_method, :method_defined?, :instance_variable_set, :to_enum] (https://eval.in/1046230)
<Caerus> someobject.methods ...
<Caerus> oh beat me to it :P
kapil___ has joined #ruby
<this_dude> dang
<this_dude> wish i knew about that before ahahaha
<this_dude> well tysm guys gonna get treat myself to a drink now
this_dude has quit [Ping timeout: 252 seconds]
mojtaba has quit [Quit: Leaving.]
noobineer has joined #ruby
Freshnuts has joined #ruby
reber has joined #ruby
cagomez has joined #ruby
cagomez has quit [Remote host closed the connection]
mcritchlow has joined #ruby
cagomez has joined #ruby
cagomez has quit [Ping timeout: 240 seconds]
mcritchlow has quit [Remote host closed the connection]
Emmanuel_Chanel has quit [Read error: Connection reset by peer]
Emmanuel_Chanel has joined #ruby
armyriad has quit [Ping timeout: 268 seconds]
thejs has quit [Quit: Leaving]
alfiemax has joined #ruby
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alfiemax has quit [Remote host closed the connection]
jameser has joined #ruby
knightblader has joined #ruby
knightblader has quit [Client Quit]
Creatornator has joined #ruby
ogres has joined #ruby
cgfbee has joined #ruby
this_dude has joined #ruby
<this_dude> hey is .chars the same as .each_char?
Creatornator has quit [Client Quit]
<this_dude> oh nvm
raulp has joined #ruby
eckhardt has joined #ruby
Inline has quit [Quit: Leaving]
mojtaba has joined #ruby
mroutis has quit [Remote host closed the connection]
noobineer has quit [Ping timeout: 248 seconds]
this_dude has quit [Ping timeout: 252 seconds]
ur5us has quit [Remote host closed the connection]
patr0clus has quit [Ping timeout: 256 seconds]
mojtaba has quit [Quit: Leaving.]
this_dude has joined #ruby
<this_dude> chat bugged out
<this_dude> need a little help
<this_dude> anyone on to assist?
<Radar> sure
<this_dude> oh didnt see your response lol
<this_dude> so
<Radar> hi
<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
<this_dude> hi lol
Eiam has quit [Ping timeout: 276 seconds]
<this_dude> this is what i have so far
apeiros has joined #ruby
cadillac_ has quit [Read error: Connection reset by peer]
<this_dude> and it works for the ones where it needs to return false
<this_dude> but its also returning false where it should return true
<this_dude> i think this is because of the statement && a[i] > a[i-1]
<this_dude> because if i==0 then i-1 == -1
<this_dude> and there is no -1 index value
<this_dude> so how can i make it so that it does that EXCEPT when the index value is already at 0
<Radar> >> a = [1,2,3,4,5]; a.sort == a
<ruby[bot]> Radar: # => true (https://eval.in/1046236)
<Radar> >> a = [5, 4, 3, 2, 1]; a.sort == a
<ruby[bot]> Radar: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<Radar> get outta town ruby[bot]
qolq has quit [Remote host closed the connection]
<this_dude> >> a = [5,4,3,2,1]; a.sort == a
<ruby[bot]> this_dude: # => false (https://eval.in/1046237)
<this_dude> you had spaces haha
<Radar> >> a = [5, 4, 3, 2, 1]; a.sort == a
<ruby[bot]> Radar: # => false (https://eval.in/1046238)
<Radar> Shouldn't matter.
<this_dude> oh wtf lol
cadillac_ has joined #ruby
<this_dude> wow
<Radar> Can we stop writing pseudo C code now?
<this_dude> literally one line of code did everything i was trying to do
<this_dude> pseudo c?
<this_dude> wdym haha
<Radar> Yes. Your code looks like C.
<this_dude> remember
<this_dude> for my exam i need to know how to do it without .sort and all that
<Radar> I still think that is a load of baloney.
<this_dude> cause that wasnt in the material given to study
<this_dude> well :/
<Radar> "Drive a car with your feet because lulzzzz"
<this_dude> thats the expectation
<this_dude> wait what XD
<Radar> with _only_ your feet
<this_dude> oh lmfao...like the flinstones?
<Radar> One foot on the steering wheel and the other on the pedals. Go on, try it.
<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
<this_dude> idk something like that
<this_dude> and because we need to know how to do it the long way?
<this_dude> to understand what the easy way is doing
<Radar> Do you though? Really?
<this_dude> do i what..need to know the long way?
<Radar> Yes.
<Radar> P.S. your code isn't checking for nils.
<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
<Radar> P.P.S. where are the minitest tests?
<this_dude> on the page im working on
<this_dude> is has those for every problem im doing
<this_dude> now to go look up what .sort does :>
<this_dude> so uh
<this_dude> is there one for integers?
<Radar> nope
<this_dude> or arrays or whatever
<this_dude> hmm
<Radar> for arrays probably.
<Radar> bbl
<this_dude> ok
<this_dude> oh yup found the one for arrays
mistym- has left #ruby ["Leaving..."]
mistym has joined #ruby
<this_dude> hmm heres a crazy one
<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"
<this_dude> whats the method to insert a character at a designated index value in an array
<blood> is this a takehome test? god help you when you take a test for real
<this_dude> numbers[4].insert("-") for example
<this_dude> im doing practice problems dude
<this_dude> i just started the language
<this_dude> im not even in school
<this_dude> and i did take a test for real...failed twice...why do you think im practicing
<blood> start with a book for the basics
<this_dude> already know the "basics" they want me to know
<this_dude> now i need to know the more advanced stuff and only have 2 more days to learn it
<this_dude> im on a time constraint to pass an exam
<blood> 2 days to learn it? sounds like someone didnt pay attention =)
<this_dude> i was given 10 days
<this_dude> to learn enough to pass an exam
<blood> no school is going to give 10 days to learn a language
<this_dude> bet?
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<blood> that doesn't prove anything
<blood> what course is this?
<this_dude> i studied and memorized all of the "prep resources" they provided
<this_dude> it nowhere near prepared me for the exam
<this_dude> so now im scrambling to memorize outside knowledge enough to pass
<this_dude> because i only have one more try to pass
duderonomy has joined #ruby
<blood> 12 week course, i would never trust anyone that tried this
<blood> this is like bootcamp
<this_dude> it is
<blood> you cram a ton of information then lose it all
<this_dude> its a coding bootcamp im applying for
<blood> do it right and pick up a book
<this_dude> if i pass the exams, free tuition AND they help set me up with a job right out of the program
<blood> and why can you not pick up a book first then attempt this bootcamp?
<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 :>
<this_dude> and i only have a couple days left
<this_dude> im been studying day in and day out
<blood> ok your choice =)
apeiros has quit [Remote host closed the connection]
<this_dude> oh it is .insert
<this_dude> just wrote the syntax wrong
camilasan has joined #ruby
<this_dude> pshh got it
<this_dude> woah this is how they did it at a higher level...can anyone explain this?
<this_dude> '(%d%d%d) %d%d%d-%d%d%d%d' % array
Nicmavr has quit [Read error: Connection reset by peer]
Nicmavr has joined #ruby
snickers has joined #ruby
<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
<blood> using an old version 1.7.2 since I'm forced to use Ruby 2.1.9 atm
DTZUZO has quit [Ping timeout: 260 seconds]
<blood> interesting, using css worked
<blood> @document.css("/weblogic-web-app/session-descriptor/cookie-name").each but xpath does not
dionysus69 has joined #ruby
herbmillerjr has quit [Quit: Konversation terminated!]
herbmillerjr has joined #ruby
za1b1tsu has joined #ruby
nowhere_man has joined #ruby
DTZUZO has joined #ruby
madhatter has joined #ruby
clemens3 has joined #ruby
TomyWork has joined #ruby
snickers has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
vondruch has joined #ruby
ogres has quit [Quit: Connection closed for inactivity]
quazimodo has quit [Ping timeout: 240 seconds]
yohji has joined #ruby
quazimodo has joined #ruby
postmodern has quit [Quit: Leaving]
mikecmpbll has joined #ruby
tty has quit [Quit: tty]
<this_dude> im burnt..ill pick this up where i left off tomorrow
snickers has joined #ruby
this_dude has quit [Ping timeout: 252 seconds]
Burgestrand has joined #ruby
sysvalve has joined #ruby
mikecmpbll has quit [Quit: inabit. zz.]
alex`` has joined #ruby
MuffinPimp has quit [Quit: Goodbye.]
mikecmpbll has joined #ruby
arup_r has joined #ruby
MuffinPimp has joined #ruby
cabotto has joined #ruby
cabotto has quit [Client Quit]
arekushi has quit [Quit: Gateway shutdown]
Puffball has quit [Remote host closed the connection]
DTZUZO has quit [Remote host closed the connection]
DTZUZO has joined #ruby
jottr has joined #ruby
unCork has joined #ruby
Cork has quit [Ping timeout: 240 seconds]
arup_r has quit []
unCork is now known as Cork
heinrich5991 has quit [Ping timeout: 268 seconds]
snickers has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
heinrich5991 has joined #ruby
aufi has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mojtaba has joined #ruby
Freshnuts has quit [Quit: Leaving]
p4p0l0 has joined #ruby
snickers has joined #ruby
snickers has quit [Client Quit]
snickers has joined #ruby
k0mpa has quit [Ping timeout: 250 seconds]
ansraliant has quit [Quit: Konversation terminated!]
dhollin3 has joined #ruby
sylario has joined #ruby
dhollinger has quit [Ping timeout: 256 seconds]
gix has joined #ruby
rootsudo has quit [Ping timeout: 244 seconds]
vondruch has quit [Ping timeout: 255 seconds]
Mike11 has joined #ruby
vondruch has joined #ruby
ferhaty has joined #ruby
alfiemax has joined #ruby
aufi has quit [Ping timeout: 265 seconds]
c0ncealed2 has quit [Remote host closed the connection]
c0ncealed2 has joined #ruby
alfiemax has quit [Remote host closed the connection]
Emmanuel_Chanel has quit [Ping timeout: 260 seconds]
psychicist__ has joined #ruby
aufi has joined #ruby
sameerynho has joined #ruby
za1b1tsu has quit [Ping timeout: 256 seconds]
apeiros has joined #ruby
aufi has quit [Ping timeout: 244 seconds]
linucks has joined #ruby
za1b1tsu has joined #ruby
sameerynho has quit [Ping timeout: 244 seconds]
za1b1tsu has quit [Read error: Connection reset by peer]
za1b1tsu has joined #ruby
jameser has quit [Ping timeout: 244 seconds]
desperek has joined #ruby
Burgestrand has quit [Quit: Closing time!]
vondruch has quit [Quit: vondruch]
doubledup has joined #ruby
za1b1tsu has quit [Read error: Connection reset by peer]
eb0t_ is now known as eb0t
za1b1tsu has joined #ruby
def_jam is now known as eblip
Mike111 has joined #ruby
Mike111 has quit [Max SendQ exceeded]
Mike11 has quit [Ping timeout: 240 seconds]
Mike11 has joined #ruby
Mike11 has quit [Max SendQ exceeded]
howdoi has joined #ruby
doubledup has quit [Remote host closed the connection]
doubledup has joined #ruby
snuz has joined #ruby
aufi has joined #ruby
arup_r has joined #ruby
gray_-_wolf has joined #ruby
ciro has joined #ruby
vondruch has joined #ruby
arup_r has quit []
aufi has quit [Ping timeout: 260 seconds]
AJA4350 has joined #ruby
sameerynho has joined #ruby
noobineer has joined #ruby
Burgestrand has joined #ruby
za1b1tsu has quit [Ping timeout: 260 seconds]
alex`` has quit [Ping timeout: 256 seconds]
noobineer has quit [Ping timeout: 255 seconds]
alex`` has joined #ruby
Dbugger has joined #ruby
r3my has left #ruby [#ruby]
jameser has joined #ruby
jcalla has joined #ruby
sysvalve has quit [Ping timeout: 268 seconds]
nowhere_man has quit [Ping timeout: 248 seconds]
jameser has quit [Quit: Textual IRC Client: www.textualapp.com]
snuz has quit [Quit: WeeChat 2.2]
salasrod has quit [Quit: /quit]
snuz has joined #ruby
salasrod has joined #ruby
MyMind has quit [Read error: Connection reset by peer]
MyMind has joined #ruby
GodFather has joined #ruby
za1b1tsu has joined #ruby
fmcgeough has joined #ruby
TJ- has joined #ruby
snickers has quit [Ping timeout: 256 seconds]
User458764 has joined #ruby
snuz has quit [Ping timeout: 265 seconds]
Inline has joined #ruby
vondruch has quit [Quit: vondruch]
alex`` has quit [Ping timeout: 244 seconds]
bmurt has joined #ruby
DarthGandalf has quit [Quit: Bye]
DarthGandalf has joined #ruby
GodFather has quit [Ping timeout: 265 seconds]
alex`` has joined #ruby
za1b1tsu has quit [Ping timeout: 276 seconds]
twe4ked has quit [Ping timeout: 265 seconds]
twe4ked has joined #ruby
za1b1tsu has joined #ruby
m27frogy has quit [Ping timeout: 268 seconds]
m27frogy has joined #ruby
gheegh has joined #ruby
za1b1tsu has quit [Ping timeout: 240 seconds]
zerowaitstate has joined #ruby
<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?
Burgestrand has quit [Quit: Closing time!]
p4p0l0 has quit [Ping timeout: 260 seconds]
<balo> zerowaitstate: what do you mean? double('MyClass', foo: :bar) ?
Burgestrand has joined #ruby
vondruch has joined #ruby
User458764 has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
ciro has quit [Ping timeout: 256 seconds]
rippa has joined #ruby
chouhoulis has joined #ruby
sameerynho has quit [Ping timeout: 240 seconds]
<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)
<balo> allow_any_instance_of(MyClass).to receive(:my_factory_method).and_return(same_object)
<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....
<balo> depending on how that factory method is implemented and how do you access it
<balo> or it can be that i still don't get the issue :)
agent_white has joined #ruby
<zerowaitstate> that may be all that is necessary. I'm still new to RSpec and the DSL is confusing me a bit
snickers has joined #ruby
snickers has quit [Client Quit]
<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
akaiiro has joined #ruby
<zerowaitstate> that makes the test brittle, because I have to know in what order each call to the factory method happens in the code.
dhollin3 is now known as dhollinger
<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
dionysus69 has quit [Ping timeout: 240 seconds]
moei has joined #ruby
Burgestrand has quit [Quit: Closing time!]
clemens3 has quit [Ping timeout: 244 seconds]
p4p0l0 has joined #ruby
<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
drale2k_ has joined #ruby
Burgestrand has joined #ruby
<darix> gray_-_wolf: the new jit added for 2.6 will bring you something similar
chouhoulis has quit [Remote host closed the connection]
za1b1tsu has joined #ruby
<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...
chouhoulis has joined #ruby
<gray_-_wolf> where could I find more on this?
<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?
<darix> gray_-_wolf: it will store the compiled version of your ruby files if it is jit worthy
<darix> gray_-_wolf: are you sure the parse time is your problem?
<balo> in general, rarely a good idea to have such complicated mocking
felix_vs has joined #ruby
<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
za1b1tsu has quit [Ping timeout: 265 seconds]
chouhoulis has quit [Ping timeout: 240 seconds]
<darix> gray_-_wolf: not sure we have something like that.
chouhoulis has joined #ruby
<ineb> zerowaitstate: balo: do i understand something wrong? cant you do expect(mock).to receive(:foo).with(bar).and_return(baz)
<gray_-_wolf> hm maybe I'll try to write it, could be interesting exercise
<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
p4p0l0 has quit [Remote host closed the connection]
ferhaty has quit [Quit: ferhaty]
<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
<ineb> for every possible input, a return value needs to be declared
<balo> ah, yeah, that can work actually. expect(MyClass).to receive(:my_builder).with(:myarg_1).and_return(my_arg_object_1)
<balo> and one line for every arg-return pair?
<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
<balo> yeah. anyway, for me this test case sounds a bit complicated
<ineb> it is. but can be used to mock subsequent db calls for every test needed
<ineb> if you dont want integration tests against a real db
<ineb> i have used it aswell for mocking http calls
gray_-_wolf has quit [Quit: WeeChat 2.2]
TJ- has quit [Ping timeout: 245 seconds]
ciro has joined #ruby
Emmanuel_Chanel has joined #ruby
Burgestrand has quit [Quit: Closing time!]
clemens3 has joined #ruby
apeiros has quit []
vondruch has quit [K-Lined]
AJA4350 has quit [Quit: AJA4350]
apeiros_ has joined #ruby
AJA4350 has joined #ruby
SeepingN has joined #ruby
akaiiro has quit [Remote host closed the connection]
apeiros_ has quit [Remote host closed the connection]
mroutis has joined #ruby
kapil___ has quit [Quit: Connection closed for inactivity]
mroutis has quit [Remote host closed the connection]
polishdub has joined #ruby
mroutis has joined #ruby
User458764 has joined #ruby
jottr has quit [Ping timeout: 256 seconds]
alex`` has quit [Quit: WeeChat 2.2]
impermanence has joined #ruby
cagomez has joined #ruby
apeiros_ has joined #ruby
gregf_ has quit [Ping timeout: 252 seconds]
hfp_work has quit [Ping timeout: 240 seconds]
apeiros_ has quit [Ping timeout: 240 seconds]
mikecmpbll has quit [Quit: inabit. zz.]
agent_white has quit [Quit: brb]
Rapture has joined #ruby
agent_white has joined #ruby
hfp_work has joined #ruby
apeiros_ has joined #ruby
AJA4351 has joined #ruby
maryo has joined #ruby
AJA4350 has quit [Ping timeout: 240 seconds]
AJA4351 is now known as AJA4350
jcarl43 has joined #ruby
herbmillerjr has quit [Quit: Konversation terminated!]
jottr has joined #ruby
AJA4350 has quit [Ping timeout: 240 seconds]
AJA4350 has joined #ruby
orbyt_ has joined #ruby
jottr has quit [Ping timeout: 248 seconds]
TomyWork has quit [Remote host closed the connection]
AJA4350 has quit [Ping timeout: 244 seconds]
howdoi has quit [Quit: Connection closed for inactivity]
yohji has quit [Remote host closed the connection]
snuz has joined #ruby
orbyt_ has quit [Client Quit]
JamJam_kid has joined #ruby
alfiemax has joined #ruby
snuz has quit [Quit: WeeChat 2.2]
maryo has quit [Quit: Leaving]
chouhoulis has quit [Remote host closed the connection]
alfiemax has quit [Remote host closed the connection]
Eiam has joined #ruby
User458764 has quit [Quit: Textual IRC Client: www.textualapp.com]
samort7 has joined #ruby
samort14 has joined #ruby
<samort14> How do I know what gems are included in the Standard Library by default?
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
armyriad has joined #ruby
<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/
samort7 has quit [Ping timeout: 244 seconds]
<samort14> mroutis: Ah, thank you! Exactly what I was looking for!
<mroutis> I don't think those modules are packaged as gems
AJA4350 has joined #ruby
<mroutis> yw, samort14 ;)
cthulchu_ has joined #ruby
snuz has joined #ruby
<samort14> mroutis: So If I want to use any of those modules, I just need to 'require' them right?
<mroutis> yes, that's right
alfiemax has joined #ruby
<samort14> mroutis: Ah, ok. Now I am understanding the difference between modules and gems
sameerynho has joined #ruby
orbyt_ has joined #ruby
Nicmavr has quit [Read error: Connection reset by peer]
<mroutis> cool! if that helps, you can read more about gems here: https://guides.rubygems.org/what-is-a-gem/
jottr has joined #ruby
Nicmavr has joined #ruby
<samort14> mroutis: Awesome! Thanks again!
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
jottr has quit [Ping timeout: 244 seconds]
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
ohcibi has joined #ruby
<havenwood> samort14: There are two types of gems that ship with Ruby, bundled gems and default gems.
felix_vs has quit [Quit: Leaving]
<havenwood> samort14: (The "bundled" name has nothing to do with Bundler.)
<havenwood> samort14: Bundled gems are not maintained by Ruby core and can be uninstalled with the `gem uninstall` command.
<havenwood> samort14: Default gems are maintained by Ruby core and cannot be uninstalled.
<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.
<havenwood> samort14: The bundled gems are did_you_mean, minitest, net-telnet, power_assert, rake, test-unit and xml-rpc.
<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
<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.
<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.
Creatornator has joined #ruby
<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
<mroutis> havenwood: today I learned ^; that's interesting
<havenwood> (Only the first eight of which were default gems in Ruby 2.4.)
felix_vs has joined #ruby
<havenwood> More of the standard library is also being gemified and removed from Ruby - which has resulted in gems like curses and tk.
tdy has quit [Ping timeout: 256 seconds]
<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
Dbugger has quit [Ping timeout: 276 seconds]
mikecmpbll has joined #ruby
darkhanb has joined #ruby
<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?
<havenwood> samort14: You can upgrade default gems without updating Ruby.
<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.
<havenwood> But yeah, you can't remove them.
<samort14> When you say 'update', what do you mean by that?
<havenwood> samort14: gem update json
<havenwood> samort14: You can have multiple versions of the JSON gem installed.
[reed] has joined #ruby
<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?
linucks has quit [Ping timeout: 240 seconds]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood> samort14: The issue is coming from this dep: https://github.com/digitalheir/ruby-xml-to-json/blob/master/xml-to-json.gemspec#L38
<samort14> Ooooh! It requires an older version of json!
<samort14> Wow! You have a good eye!
bmurt has joined #ruby
<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'
tty has joined #ruby
<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?
<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
<havenwood> samort14: You can just manually `to_hash.to_json` or implement just what you need. It should only be a few lines.
<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.
felix_vs has quit [Quit: Leaving]
<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.
<havenwood> samort14: With gems, we add the Gemfile.lock to the .gitignore.
tdy has joined #ruby
<havenwood> With apps, you ship the Gemfile.lock so every dev is using the exact same gems and versions when running the app.
<samort14> havenwood: Ah, wow, this is all super useful information! Thank you guys so much!
<havenwood> samort14: No prob. Happy coding!
<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/
jcarl43 has quit [Read error: Connection reset by peer]
<samort14> +1000 I'm definitely going to use that!
jcarl43 has joined #ruby
* baweaver wanders in
<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
snickers has joined #ruby
JamJam_kid has quit [Remote host closed the connection]
<baweaver> >> h = {a: 1, b: 2, c: 3}; h.keys.map(&h)
<ruby[bot]> baweaver: # => [1, 2, 3] (https://eval.in/1046586)
* baweaver slowly backs away
<havenwood> baweaver: Ruby 2.6: {a: 1, b: 2, c: 3}.then { |h| h.keys.map &h } #=> [1, 2, 3]
<havenwood> baweaver: That's a convoluted way to say "values"!
<baweaver> Want to know where it becomes useful?
cadillac_ has quit [Ping timeout: 240 seconds]
<havenwood> Case statements?
<havenwood> baweaver: where?
<havenwood> <3 #filter and #then aliases in 2.6
snickers has quit [Ping timeout: 245 seconds]
<havenwood> I know some folk don't like #then, but wheeee!
<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 }
<ruby[bot]> baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<baweaver> ...bad bot
<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 }
<havenwood> #=> 0
<havenwood> #=> 0
<ruby[bot]> baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<baweaver> havenbot wins.
cadillac_ has joined #ruby
mroutis has quit [Remote host closed the connection]
impermanence has quit [Ping timeout: 240 seconds]
marius has quit [Ping timeout: 245 seconds]
snuz has quit [Quit: WeeChat 2.2]
snuz has joined #ruby
nowhere_man has joined #ruby
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mroutis has joined #ruby
snuz has quit [Ping timeout: 240 seconds]
snuz has joined #ruby
tag has joined #ruby
marius has joined #ruby
akaiiro has joined #ruby
r29v has joined #ruby
marius has quit [Ping timeout: 256 seconds]
User458764 has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
weaksauce has quit [Ping timeout: 244 seconds]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
this_dude has joined #ruby
<this_dude> hey guys goodmornin
User458764 has quit [Client Quit]
User458764 has joined #ruby
darkhanb has quit [Read error: Connection reset by peer]
User458764 has quit [Client Quit]
User458764 has joined #ruby
marius has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
alfiemax has quit [Remote host closed the connection]
User458764 has joined #ruby
ellcs has joined #ruby
bmurt has quit [Remote host closed the connection]
User458764 has quit [Client Quit]
marius has quit [Ping timeout: 256 seconds]
bmurt has joined #ruby
User458764 has joined #ruby
User458764 has quit [Client Quit]
<samort14> Good morning :)
User458764 has joined #ruby
TJ- has joined #ruby
drale2k_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
User458764 has quit [Client Quit]
jcarl43 has quit [Quit: WeeChat 2.2]
jcarl43 has joined #ruby
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
jottr has joined #ruby
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
weaksauce has joined #ruby
sauvin has quit [Read error: Connection reset by peer]
GodFather has joined #ruby
User458764 has quit [Client Quit]
marius has joined #ruby
dviola has joined #ruby
SirFunk has quit [Quit: ZNC - http://znc.in]
AJA4350 has quit [Ping timeout: 240 seconds]
SirFunk has joined #ruby
AJA4350 has joined #ruby
snuz has left #ruby [#ruby]
PettanShoutaKun has joined #ruby
marius has quit [Ping timeout: 256 seconds]
<PettanShoutaKun> https://gist.github.com/TheeRFG/2dfe526b7bd7c2c15b337abfc73ddf90 will something like this give me time in seconds?
<this_dude> its loading just a sec
snuz has joined #ruby
snuz has quit [Client Quit]
<this_dude> hmm
<this_dude> good question
<PettanShoutaKun> provided that only seconds have passed between those two time periods?
<this_dude> ^
<this_dude> yeah cause if its greater than a 60 minute difference
<this_dude> it'll return it in hours:minutes
<PettanShoutaKun> awesome, thank you!
<this_dude> do me a favor...
<this_dude> take a look at my code and see if any obvious errors stick out?
akaiiro has quit [Ping timeout: 248 seconds]
snuz has joined #ruby
alfiemax has joined #ruby
<this_dude> the method should take in a string of numbers and return a digital root
<this_dude> (the sum of all characters repeated until youre left with a one digit integer)
<this_dude> I.E. 942 returns 6
fmcgeough has quit [Quit: fmcgeough]
alfiemax has quit [Ping timeout: 260 seconds]
dionysus69 has joined #ruby
<ineb> this_dude: or [1,2,9,2,3].inject { |sum, n| new_sum = sum + n; break sum if new_sum > 9; new_sum ; }
<ineb> >> [9,4,2].inject { |sum, n| new_sum = sum + n; break sum if new_sum > 9; new_sum ; }
<ruby[bot]> ineb: # => 9 (https://eval.in/1046609)
<this_dude> that returned an incorrect response^
<ineb> right ^^ u said 6
<this_dude> yeah
<this_dude> this one is giving me some trouble haha
<this_dude> been stuck since yesterday
spiette_ is now known as spiette
mroutis has quit [Ping timeout: 240 seconds]
<this_dude> i think the error in yours is the "break sum if new_sum > 9"
<this_dude> cause i need it to rerun the loop if its greater than 9
<this_dude> break sum if new_sum.length == 1
<this_dude> ?
<baweaver> What's the link to the question?
<baweaver> input.chars.map(&:to_i)
<baweaver> Ah.
<havenwood> 942.digits.sum #=> 15
<this_dude> but then i need it to do that again^
<this_dude> to give me 6
<havenwood> 15.digits.sum #=> 6
<this_dude> im having trouble setting the parameter of "stop when result.length == 1"
<ineb> havenwood: nice one
<baweaver> havenwood: when was digits introduced?
<ineb> should be easy then
<havenwood> baweaver: 2.4
<this_dude> hey so
<baweaver> Now why did RVM put me back on 2.3....
<this_dude> i kinda got it?
<this_dude> but not quite
<this_dude> n.digits { |sum, n| new_sum = sum + n; break sum if new_sum.length == 1; new_sum ; }.join.to_i
<this_dude> something is wrong here
<this_dude> not sure what
<havenwood> >> n = 942; loop { break n if n.digits.one?; n = n.digits.sum }
<ruby[bot]> havenwood: # => undefined method `digits' for 942:Fixnum (NoMethodError) ...check link for more (https://eval.in/1046611)
<havenwood> #=> 6
<baweaver> def digital_root(n) n.digits.sum.yield_self { |s| s.digits.size == 1 ? s : digital_root(s) } end; digital_root(942)
<baweaver> To understand recursion you must first understand recursion.
<this_dude> ;-;
<baweaver> ah, right, `one?`
<this_dude> excuse me
<baweaver> def digital_root(n) n.digits.sum.yield_self { |s| s.digits.one? ? s : digital_root(s) } end; digital_root(942)
marius has joined #ruby
<this_dude> idk whats going on
<baweaver> Do you know what factorial numbers are?
<this_dude> guys i need to know how to write this without maps and stuff XD
<baweaver> 5! = 120
<this_dude> yeah...5*4*3*2*1
<baweaver> That's a silly constraint.
<this_dude> well its whats needed for my exam remember .-.
<baweaver> Where does it say you can't though?
<baweaver> It says you don't _need_ them
<baweaver> not that you _can't_ use them.
<this_dude> thats what i have so far^
<this_dude> and you're right
<baweaver> So would it be fair to say Factorial 5 (5!) could be expressed as 5 * 4! ?
<this_dude> but for time constraint's sake
<this_dude> shouldnt i just learned to do it the long way
<baweaver> That's the trick though
<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)"
<this_dude> means
<baweaver> If you know the type you're operating on (Array, Enumerable, Hash, String, Integer) you can find its methods
<baweaver> and if you can find those you can get those methods
<this_dude> i bookmarked the dictionaries of methods for each of those by the way hehehe
<baweaver> >> def factorial(n) n < 2 ? n : n * factorial(n - 1) end; factorial(5)
<ruby[bot]> baweaver: # => 120 (https://eval.in/1046612)
<this_dude> o-o
<baweaver> If n is less than 2, return n, otherwise return n multiplied by the factorial of n minus one.
<havenwood> Enumerator.generate(942) { |n| raise StopIteration if n.digits.one?; n.digits.sum }.reverse_each.first #=> 6
<this_dude> couldnt you just...if n is less than 2, return n, otherwise return factorial of n
<this_dude> lol
<baweaver> so 5! -> 5 * 4! -> 5 * 4 * 3! -> 5 * 4 * 3 * 2! -> 5 * 4 * 3 * 2 * 1
<this_dude> what is "enumerator"?
<baweaver> you take a problem you don't know the answer to and break it into smaller concepts until you do know an answer
<havenwood> Enumerator.generate(942) { |n| n.digits.sum }.find { |n| n.digits.one? } #=> 6
<this_dude> and "raise stopiteration"
<havenwood> this_dude: Stuff.
<baweaver> generate isn't even in core is it?
<this_dude> ok but like
<this_dude> youre blowing my mind
<this_dude> ouch
<havenwood> baweaver: Nope, proposed for 2.6: https://github.com/zverok/enumerator_generate#readme
GodFather has quit [Ping timeout: 240 seconds]
<baweaver> proposed, yes
<baweaver> but not in
<this_dude> ahahahahaha i tried to copy paste that and got
<this_dude> "endefined method "generate"
<havenwood> this_dude: The Enumerator#generate method isn't in Ruby yet. It was proposed for 2.6.
<this_dude> D:
<this_dude> so how do i do this in ruby then
<this_dude> ugh
mojtaba has quit [Remote host closed the connection]
<this_dude> i want to understand the long way to do it
<this_dude> then learn the easy way
<this_dude> cause i dont get why my long way isnt working
<this_dude> it works for some, and not for others
<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
* this_dude is very confused and mindblown
<this_dude> currently processing that..
<havenwood> this_dude: In Ruby you can make your own Enumerator collections.
jasmith has quit [Ping timeout: 265 seconds]
<this_dude> oh wait can i just ...while n.length>1; n = n.digits.sum; return n
<havenwood> this_dude: yup
<this_dude> wtf
<this_dude> i feel stupid..again
<this_dude> oh wait
<this_dude> but what if n is just..7
<this_dude> it'll return nil
<this_dude> how do i stop that?
<havenwood> baweaver: If all goes well, in 2.6...!: Enumerator.generate(942, &:digits << :sum).find(&:digits << :one?) #=> 6
<havenwood> Actually, I should write a quick gem for the shovel proc compositions: https://gist.github.com/havenwood/d305b42f5b542e9de1eaa8e56ba6bdd7
<havenwood> That's a nice thing about Ruby, we can easily implement these features in a few lines until they're formally introduced.
<this_dude> hmm
<this_dude> so it worked for all but one of my minitests
<this_dude> nevermind..typoed the minitest..it works
<this_dude> i feel incompetent because i struggled on that for so long
<this_dude> i cant find an article on .digits
<this_dude> found the article nvm
<havenwood> I love we can make this work in ~20 lines...:
<havenwood> Enumerator.generate(942, &:digits << :sum).find(&:digits << :one?)
<havenwood> <3 Ruby
<this_dude> jesus
<this_dude> so much code
<havenwood> this_dude: That's pretty little code considering it implements function composition and a new way to generate an Enumerator!
<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
<this_dude> we dont lmao.
<havenwood> this_dude: None of the cows were vegetarians?
<this_dude> XD
<this_dude> I'll tell her that
<this_dude> "Ma'am all of our cows were vegetarians is that what you meant?"
<this_dude> ahahaha
<this_dude> can i call you shannon
<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
eam has quit [Changing host]
eam has joined #ruby
maryo has joined #ruby
<this_dude> i feel like if i read that ill just end up more confused than before so ill stick to my basics xD
<havenwood> this_dude: Yeah, no need to look into implementation details unless you're just curious and have lots of time.
<this_dude> maybe later
<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
solidsnack has quit [Ping timeout: 245 seconds]
spiette has quit [Remote host closed the connection]
<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."
mroutis has joined #ruby
PettanShoutaKun has quit [Ping timeout: 252 seconds]
spiette has joined #ruby
solidsnack has joined #ruby
<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?
<baweaver> maryo: What does the first line of the error say?
<baweaver> `include?`
<maryo> baweaver, first line of the error? it says "scheduler caught exception:
<maryo> "
<baweaver> Now the second line
<this_dude> ty
mojtaba has joined #ruby
snuz has quit [Quit: WeeChat 2.2]
<maryo> baweaver, here it is undefined method `[]' for nil:NilClass
<baweaver> >> nil['nope']
<ruby[bot]> baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<baweaver> Does that error look familiar?
<baweaver> ( havenwood - Oh I know )
<maryo> baweaver, yep but I am wondering from where I am getting that nil value
<this_dude> oh .count
<baweaver> Line #3
<baweaver> from get_build_info
chouhoulis has joined #ruby
<maryo> baweaver, you mean this line https://dpaste.de/gFqf#L94 ?
<baweaver> Keep tracing it backwards until you find where bad info got into the pipeline
jcalla has quit [Quit: Leaving]
<maryo> baweaver, Is it possible to get the value of result for debugging purpose ? like p result ? by adding it to line 155
tdy has quit [Ping timeout: 245 seconds]
<baweaver> You could certainly try it.
<baweaver> ?pry
<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
<baweaver> That may help
<this_dude> i think im using .count wrong lol
<maryo> thank you baweaver o/
maryo has quit [Quit: Leaving]
<baweaver> you're missing an end as well
mojtaba has quit [Ping timeout: 240 seconds]
<this_dude> yeah i saw that hah
<baweaver> So you want to get a count of xs and os?
<this_dude> but am i using .count wrong or something?
<this_dude> yeah
beefjoe has joined #ruby
<baweaver> Contrived 30 second implementation: str.downcase.chars.group_by(&:itself).values.map(&:count).uniq.one?
fmcgeough has joined #ruby
tdy has joined #ruby
jottr has quit [Quit: WeeChat 2.2]
<this_dude> o-o
dionysus69 has quit [Quit: dionysus69]
<this_dude> why you gotta make everything so complicated D:
<this_dude> so high level**
<baweaver> Nicer way: counts = str.downcase.chars.each_with_object(Hash.new(0)) { |c, counts| counts[c] += 1 }; counts[0] == counts[1]
<this_dude> jesus
<this_dude> "nicer"
<baweaver> 2.6+, if accepted: str.downcase.chars.histogram.values.uniq.one?
<this_dude> according to ruby-doc.org .count is used like so
<this_dude> thats the image they provide
<this_dude> oh to include multiple letters you just... .count "xX" .count "oO"
oncall-pokemon has joined #ruby
<this_dude> but my comparison statement returns an error
<this_dude> whats wrong here lol
<this_dude> doesnt make sense to me
GodFather has joined #ruby
<this_dude> nvm i got it
<this_dude> by doing it the long way https://dpaste.de/9Pi4
<this_dude> str.downcase.count('x') == str.downcase.count('o') was the answer
<this_dude> but i tried that and got an error...
eckhardt_ has joined #ruby
mroutis has quit [Remote host closed the connection]
gheegh has joined #ruby
<this_dude> how do you coerce a range into integers
<this_dude> such as
<this_dude> [a..b].sum.to_i
<this_dude> or something like that
mojtaba has joined #ruby
NightMonkey has quit [Quit: ZNC - http://znc.in]
NightMonkey has joined #ruby
apeiros_ is now known as apeiros
<apeiros> >> (10..20).sum # this_dude
<ruby[bot]> apeiros: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<this_dude> already found it
<this_dude> ty though
<apeiros> meh, we really need something more reliable than eval.in :(
<this_dude> its (a..b).to_a.sum
<apeiros> that's less efficient
<this_dude> >> (10..20).to_a.sum
<ruby[bot]> this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<apeiros> you can just drop the .to_a
<this_dude> gave me an error when i did
<apeiros> which ruby version?
<this_dude> idk im on codewars.com
<apeiros> also what error exactly?
<this_dude> oh wait not its not giving me that error wtf dude lol
<this_dude> now*
<this_dude> nvm
<apeiros> also, sum of a range can be calculated directly ;-)
* apeiros wonders whether Range#sum special cases that
<this_dude> the range isnt given
<this_dude> only two integers
<this_dude> i have to make the range inside my method
<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."
<apeiros> hm, now I wonder whether the direct calculation also works for negative numbers…
<this_dude> i have a problem though
<this_dude> my code is working for all except one minitest
<this_dude> 5 and -1
<this_dude> its returning nil for some reason
<apeiros> do you create a range 5..-1 from it?
<apeiros> or -1..5?
<this_dude> i created an if statement for if the second integer is the smaller one
<this_dude> it should take that into account idk whats going wrong
<havenwood> this_dude: (42..1).size #=> 0
<this_dude> wut
<apeiros> looks to me like your code is correct
<this_dude> my code should be creating a range from -1 to 5
<this_dude> then wtf lol
<apeiros> you could simplify it since (n..n).sum == n
<this_dude> oh i ran it agin
<this_dude> again* and now it worked
<this_dude> wtf XD
<this_dude> glitch?
<this_dude> oh you right
<havenwood> >> (42..42).sum
<this_dude> wait thats it
<apeiros> i.e. `a,b = b,a if b < a; (a..b).sum` is sufficient
<ruby[bot]> havenwood: I'm terribly sorry, I could not evaluate your code because of an error: OpenURI::HTTPError:500 Internal Server Error
<havenwood> #=> 42
<this_dude> when i remove the " elsif a == b "
<this_dude> line it gives me the nil
<this_dude> for 5 and -1
<this_dude> why tf
duderonomy has quit [Ping timeout: 256 seconds]
<apeiros> because you still have a condition
<apeiros> none of your branches is it
<this_dude> wdym
<this_dude> my dogs name is duderonomy LOL
<this_dude> -1 < 5
<this_dude> so it should execute line 4 no??
<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
<this_dude> but thats what im saying...doesnt 5 and -1 meet the condition of line 4 https://dpaste.de/FMda#L
<havenwood> this_dude: Range.new(*[41, 1].sort).sum #=> 861
<apeiros> this_dude: yes. I thought you were talking about a == b giving you nil.
<this_dude> no
ellcs has quit [Remote host closed the connection]
<this_dude> when i dont include that line the minitest using (5,-1) returns nil
<this_dude> no idea why
<apeiros> paste the code
<this_dude> the minitest code?
<this_dude> or my code
<this_dude> https://dpaste.de/FMda#L is my code
<this_dude> Test.assert_equals(get_sum(5,-1),14)
<havenwood> this_dude: both. a gist can have multiple files and be updated.
<this_dude> is the minitest code that returns nil if i take out lines 6 and 7
beowuff has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
<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
<this_dude> exactly my poiny
ellcs has joined #ruby
<this_dude> point* no idea whats going on
<apeiros> (and does so for me)
<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`?
<this_dude> correct
<havenwood> this_dude: So what should your if/else condition be to express that?
<this_dude> dude i ran it again and now i dont get the error
<this_dude> im so done
<this_dude> this website is broken af
<this_dude> oo oo pop quiz
<this_dude> gimme a sec
<havenwood> this_dude: That's a reason stuff like https://exercism.io/ is great - you run the tests locally.
<this_dude> what i have no?
<this_dude> if a < b (a..b).sum elsif b < a (b..a).sum
<havenwood> this_dude: "all other cases" is just: else
<this_dude> oh
<this_dude> rip
<this_dude> if a < b (a..b).sum else (b..a).sum
<this_dude> ?
<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`?
<this_dude> wait no
<apeiros> alternatively <=, but just else is better.
<this_dude> yeah
<this_dude> ok cool ty
mojtaba has quit [Quit: Leaving.]
<this_dude> and i guess this is how you do it in one line
<this_dude> return a < b ? (a..b).reduce(:+) : (b..a).reduce(:+)
<this_dude> no idea what that means though
beefjoe has quit [Ping timeout: 272 seconds]
<havenwood> this_dude: that was the days before #sum
Creatornator has joined #ruby
<this_dude> oh eww
<this_dude> ooo this next problem is interesting
<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.
<havenwood> this_dude: b < a ? (b..a).sum : (a..b).sum
<this_dude> oh wow
<apeiros> reduce, aka inject will "inject" the operator between every element, i.e. [1,2,3].inject(:+) "becomes" 1 + 2 + 3
<havenwood> this_dude: that is called a "ternary" operator
<havenwood> this_dude: CONDITION ? IF_TRUTHY : IF_FALSEY
<cthulchu_> folks, what does it do? https://paste.ofcode.org/kpRT7utdkZsHrFusCTRvjZ
<cthulchu_> how does it work
<havenwood> this_dude: It's probably better for you to write it: if b < a; (b..a).sum; else; (a..b).sum; end
<cthulchu_> the all_possible_values is just a hash that has all these fields set
r29v has quit [Quit: r29v]
<apeiros> cthulchu_: it's an array literal? not sure what part about it you're having trouble with…
<cthulchu_> it creates all combos of that hashes fields vals...
<apeiros> not the code you pasted, no.
<havenwood> cthulchu_: You've showed us a Hash literal. That's all.
<cthulchu_> oh, ok, will continue looking for it
<apeiros> havenwood: array literal. please :-p
<apeiros> (containing hash literals, sure)
<havenwood> apeiros: :-O, Staring at a Hash, trying to write Array. Haha, oops.
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<this_dude> is there a way to like... .filter(class:string)
<havenwood> An Array of two mystery Objects, and at least 10 Hashes.
<this_dude> or something like that
<havenwood> this_dude: We use #select for filtering. It gets a #filter alias in 2.6.
<havenwood> this_dude: Or there's a #grep.
<this_dude> or .gsub?
<cthulchu_> also what's each_with_index?
<havenwood> this_dude: ['hi there', :no_not_gsub, 42, 'just strings'].grep String
<cthulchu_> I mean, is there anything in an array that wouldn't have an index?
<havenwood> this_dude: #=> ["hi there", "just strings"]
<havenwood> cthulchu_: Everything in an Array has an index.
<cthulchu_> so then what's the point of doing each_with_index to an array?
<cthulchu_> it would do just the same as .each?
<havenwood> chamunks: [:a, :b, :c].each_with_index.to_h #=> {:a=>0, :b=>1, :c=>2}
<havenwood> cthulchu_: ^
<apeiros> the index is implicit
<apeiros> each does not yield the index
<apeiros> only the element
<cthulchu_> ah, I see
<cthulchu_> thanks
<havenwood> cthulchu_: Check it in IRB or Pry: [:a, :b, :c].each_with_index.to_a
<this_dude> whats the difference between .grep and .gsub
<cthulchu_> it's just to get the index variable inside the block
<cthulchu_> makes sense
<this_dude> get replace and get substitute
<this_dude> isnt it?
<this_dude> i thought its the same thing lol
gheegh has joined #ruby
<cthulchu_> lol
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<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).
<this_dude> google isnt helping
jcarl43 has quit [Read error: Connection reset by peer]
jcarl43 has joined #ruby
<havenwood> JJonah: Do you want to run your own gem server then?: https://guides.rubygems.org/run-your-own-gem-server/
y3n has joined #ruby
<JJonah> havenwood: Is geminabox still well maintained? "Latest commit bf71f9b on Jun 15"
cjkinni has joined #ruby
<JJonah> Also, does it come with any kind of built in search?
<apeiros> we use geminabox at work. runs fine.
<havenwood> JJonah: it works and everything
<this_dude> ok so apparently .replace doesnt work the way i thought it does
<this_dude> what would i put instead of .replace
<this_dude> i want every character other than the last 4 of any string to replaced with "#"
<this_dude> oh nvm
<this_dude> forgot to actually store the replace value
<this_dude> cc[i]=cc[i].replace('#')
jcarl43 has quit [Ping timeout: 256 seconds]
dviola has quit [Quit: WeeChat 2.2]
<this_dude> im learning guys! i almost feel ready for my last attempt at the exam haha
Creatornator has joined #ruby
<apeiros> replace replaces the complete object
<apeiros> gsub and String#[]= are suitable here
<this_dude> no idea how to use thsoe
<apeiros> for similar cases (IMO not this one, though), tr and delete can also be a choice
<this_dude> those*
<this_dude> so
<JJonah> this_dude: try something like this instead and avoid loops: http://dpaste.com/07NJ4WP
<apeiros> be wary of edge-cases JJonah ;-)
<this_dude> o-o
<this_dude> i have no idea what that code is even doing lmaooo
<apeiros> but String#[] & + is indeed the better choice than via #[]=
<JJonah> this_dude: it's Xing out every char but the last 4
<JJonah> apeiros: which edge case are you thinking?
<this_dude> well i figured but
<apeiros> JJonah: short string
<this_dude> i cant follow the syntax lol
<JJonah> apeiros: if it's a cc number though, should be fine
<apeiros> never trust user input :) but yes, if you know the value has been validated beforehand, you can skip code to handle edge cases.
<JJonah> apeiros: yeah, i was assuming that was the case
<apeiros> I assume the opposite unless expressly being told :)
<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.
<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.
cjkinni has quit [Quit: Ping timeout (120 seconds)]
gnufied__ has quit [Remote host closed the connection]
<this_dude> y'all are way above my level and its so entertaining to read lmao
cjkinni has joined #ruby
<this_dude> explain to me please how this works
<this_dude> cc.gsub(/.(?=....)/, '#')
<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.
<this_dude> i still dont understand hashes or whatever this is
<apeiros> this_dude: what do you know about regexes so far?
<this_dude> nada
<this_dude> that wasnt in the course material
<this_dude> and its all very confusing
<JJonah> ooohh that regex solution is nice. that's better than mine.
psychicist__ has quit [Ping timeout: 265 seconds]
<apeiros> ok, then the high-level explanation: gsub(/.(?=....)/, "#") replaces every character which is followed by any 4 characters with a #
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
patr0clus has joined #ruby
<apeiros> JJonah: dunno, I like yours more tbh.
gheegh has joined #ruby
<this_dude> 0-0
<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)
<apeiros> and // is the delimiter for the regex (like "" is for strings)
<apeiros> within the regex, . means "any character"
<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.
plutes has joined #ruby
<apeiros> and (?=…) means "followed by …" (the term is "positive look-ahead")
<this_dude> wild
<this_dude> so complicated
<apeiros> so (?=....) is "followed by 4 characters"
<this_dude> im kinda following
<apeiros> but a (?=) group is itself not part of the match, hence it's not replaced, only the first .
<this_dude> (?={4}) == (?=....)
<this_dude> ?
<apeiros> almost
<apeiros> (?=.{4})
<this_dude> f***
<this_dude> why
<apeiros> you still need to quantify something :)
<this_dude> i dont quite follow
<apeiros> {4} means "4 of the atom to the left", but you have nothing to the left of it :)
<apeiros> .{4} means "4 of ."
<apeiros> a{4} means "4 of 'a'"
<baweaver> oh no
<this_dude> crazy
<this_dude> hey weaver
<apeiros> useful
<this_dude> theyre teaching me regexes
<baweaver> Pandoras box has opened
<apeiros> run while you can 😄
<this_dude> knowing you, you probably have an illustrated course on it dnot you
<this_dude> dont*
<this_dude> XD
<baweaver> ..........
<baweaver> maybe
<apeiros> there certainly is a regex lemur
<this_dude> ahahahhahahahaha
<this_dude> you so would lmaooo
<this_dude> i admire that though
<this_dude> dont get me wrong
<this_dude> i wish i had the understanding of the language yall do
<this_dude> omg XD
<apeiros> needs two wands, though, so they can form the // :D
<baweaver> It's not done
<baweaver> or really all that fleshed out.
<apeiros> baweaver, you're a treasure :D
<this_dude> so this is actually my first programming language not including Robot-C in case yall couldnt tell
<this_dude> what else do y'all code in?
<apeiros> this_dude: you're doing fine
<baweaver> Mind that I stopped updating that version. You'll all see why later.
<this_dude> "<apeiros> baweaver, you're a treasure :D" agreed
<apeiros> this_dude: almost exclusively ruby & js. I do know a couple of other languages. not nearly as fluent in those, tho
<baweaver> Ruby, Javascript, Scala, Haskell*, F#*, Python, Go*, Rust* (*but not strongly)
<this_dude> as soon as i become "proficient enough"in ruby im jumping straight back into python
<this_dude> i tried once before and just couldnt wrap my head round it
<baweaver> Eh, I just don't like the feel of Python
<this_dude> python and objective C are used for sooooo many things now
<this_dude> and violent python is my dream to be able to put into practice
<baweaver> With any luck the lemurs will be at RubyConf this year.
<this_dude> theres...
<this_dude> a rubycon?!
<cthulchu_> I have a quick stupid question, folks. How do I add an explicit key-val to a hash? like hashA,push({a:123})
<baweaver> Several. I spoke at Southeast Ruby
<cthulchu_> oh, no
<this_dude> pretty sure its not a stupid question since idek what that means lol..
cjkinni has quit [Quit: Ping timeout (120 seconds)]
<cthulchu_> just hashA[a]=123?
<baweaver> cthulchu_: what have you tried?
<baweaver> you want a colon before it, but yes.
<cthulchu_> a colon where?
cjkinni has joined #ruby
<baweaver> before the a
<baweaver> hash[:a] = value
<cthulchu_> wow
<cthulchu_> ok, interesting, thanks
<cthulchu_> would hash.a = value work?
<baweaver> Nope
<baweaver> not Javascript.
<cthulchu_> ok :(
<cthulchu_> what about hash:a?
<apeiros> there's also Hash#store
<baweaver> Also no
<apeiros> but nobody uses that :D
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<cthulchu_> should we use hash store?
<baweaver> Southeast Ruby: https://2018.southeastruby.com/
<baweaver> No, not really
<apeiros> there's no reason to, no
<cthulchu_> ok, cool, thanks
<apeiros> it's an alias and []= reads nicer.
<cthulchu_> but I guess that method gets called implicitly
<cthulchu_> aha, ok
<baweaver> Now are there ways to _make_ ruby do those things? Sure, but don't do it.
<baweaver> It's slow and prone to errors.
<apeiros> cthulchu_: re hash.a = value, take a look at OpenStruct
<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.
<apeiros> but baweaver's slow & prone comment is of course on-point :)
<baweaver> Hehe, OpenStruct kills method cache too
<apeiros> I even try to avoid hashes if I can and use Struct instead
mroutis has joined #ruby
<this_dude> im trying to think how you would do this mathematically
<apeiros> baweaver: is that still an issue? I somehow thought that was resolved?
<apeiros> baweaver: along with extend
<this_dude> string[string.length/2]
<baweaver> havenwood: ^
<baweaver> He'd know.
gheegh has joined #ruby
Rapture has quit [Quit: Textual IRC Client: www.textualapp.com]
<this_dude> guys?
reber has quit [Remote host closed the connection]
<this_dude> oooo yes "string[string.length/2]" is a valid statement
<this_dude> works in irb
<this_dude> hehehe
<baweaver> >> def whittle(str) str = str[1..-2] until str.size < 3; str end; [whittle('bob'), whittle('sees'), whittle('things')]
<ruby[bot]> baweaver: # => ["o", "ee", "in"] (https://eval.in/1046627)
<cthulchu_> so I can do something like field_test_combinations[index][:index]=index
<cthulchu_> given that the array is a collection of hashes
paraxial has quit [Quit: The Lounge - https://thelounge.github.io]
<cthulchu_> I just want to put hash index into the hash
paraxial has joined #ruby
<cthulchu_> actually that :index should be a string since it's a key
<this_dude> um
<cthulchu_> so it should be field_test_combinations[index][:"index"]=index
<cthulchu_> right?
duderonomy has joined #ruby
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<apeiros> cthulchu_: ruby has a hash-key equality protocol, which allows you to use virtually any object as a key, not just strings.
<apeiros> I really miss that in JS' Map :(
<cthulchu_> never needed anything more than a string as a key
<cthulchu_> but ok
alex`` has joined #ruby
<this_dude> @baweaver i did it like this https://dpaste.de/GOKk
<this_dude> wow i couldve just..
<this_dude> s[(s.size-1)/2..s.size/2]
<this_dude> hey what was the method to remove spaces again?
<apeiros> .strip?
<apeiros> that's from the head & tail. .delete if from anywhere in the string.
<this_dude> .oh strip
<this_dude> ohh ok
<this_dude> .delete
<this_dude> cool ty
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
samort14 has quit [Quit: Leaving]
<cthulchu_> a=b?b=a:false
<cthulchu_> is that how you end the ternary?
<cthulchu_> or just :nil
<apeiros> o0
<this_dude> shoot im lost
<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
thy0 has joined #ruby
<this_dude> string.to_a.delete(" ")
<this_dude> ?
<apeiros> this_dude: don't delete the spaces.
<apeiros> take a look at String#split
<this_dude> wdym
<this_dude> OH DUH
<this_dude> i forgot about split
<this_dude> smh
<this_dude> string.split(" ")
<this_dude> i forgot the basics lmao
ur5us has joined #ruby
<this_dude> ok problem
<this_dude> when i do that
<this_dude> its storing the numbers as string values right?
<this_dude> i need them as integers
<this_dude> cause for some reason if i do string=string.split(" "); return string.max + " " + string.min
<this_dude> i dont get the correct response
<apeiros> probably because "10" < "2", while 10 > 2 :)
<this_dude> ok so how do i change that
<apeiros> check string's docs, I'm sure you'll find a way to convert a string to integer
<this_dude> well obv .to_i
<this_dude> but where do i put that
<this_dude> before .split? or after
<apeiros> which would make more sense?
<this_dude> numbers.split(" ")
<this_dude> oops hit enter too early
<this_dude> wait
<this_dude> numbers=numbers.split(" "); numbers=numbers.to_i
<this_dude> ?
mroutis has quit [Ping timeout: 240 seconds]
<this_dude> that doesnt do anything :(
<this_dude> agh
polishdub has quit [Quit: leaving]
<apeiros> well, numbers.split returns an array
<apeiros> you can't call to_i on an array. but the elements in the array are strings.
alfiemax has joined #ruby
AJA4350 has quit [Ping timeout: 256 seconds]
<this_dude> wtf man
<cthulchu_> omfg
<cthulchu_> byebug is so extremely useful!
<cthulchu_> I made a wrapper for it
AJA4350 has joined #ruby
<this_dude> OH
<this_dude> numbers.map { |n| n.to_i }
<this_dude> ???
<apeiros> 👍🏻👏🏻
<this_dude> im on pc..cant see those characters
<this_dude> are those emojis
<cthulchu_> hehe
<this_dude> did i get the answer right or no?
<this_dude> xD
<apeiros> this_dude: thumbs-up + clap
<this_dude> oh shoot
alfiemax has quit [Ping timeout: 240 seconds]
<this_dude> im learning
<apeiros> and shouldn't pc's be able to display emojis too?
<this_dude> woah
ellcs has quit [Ping timeout: 256 seconds]
<this_dude> my pc is from like.. 2008 XD
<this_dude> it originally ran on vista
<this_dude> lmfao
<this_dude> wtf
<apeiros> ok, not adept with windows. but my wife's macbook from 2010 can display emoji with no problems :D
<this_dude> "string cant be coerced into integer"
<apeiros> you get that when you do something like 1 + "2"
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<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
<this_dude> oh wait you're right
<apeiros> of course. I'm always. Even when I'm not. :D
<this_dude> forgot .to_s
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<baweaver> >> '1 2 3 4 5'.split.map(&:to_i).sum
<ruby[bot]> baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
alex`` has quit [Ping timeout: 244 seconds]
<this_dude> done https://dpaste.de/PvTi
nowhereman_ has joined #ruby
<apeiros> this_dude: two stylistic things:
<apeiros> 1) you can scrap the return
<apeiros> 2) we usually prefer "#{numbers.max} #{numbers.min}" over numbers.max.to_s + " " + numbers.min.to_s
nowhere_man has quit [Ping timeout: 256 seconds]
<this_dude> o-o
<apeiros> note that #{} will call to_s on any non-string value.
<this_dude> didnt know that
<this_dude> cool
mikecmpbll has quit [Quit: inabit. zz.]
<apeiros> hence "1 + 2 = #{1+2)" is fine
<apeiros> whoops
<apeiros> apart for the ) vs. } mishap, of course
<this_dude> so i could do
<this_dude> #{numbers.max+numbers.min}
<this_dude> ?
beowuff has joined #ruby
<this_dude> oh wait no cause i need the space
<baweaver> apeiros: tsk tsk tsk
<this_dude> nvm
<this_dude> ahh! the lady calls..gotta go folks..bbl! tysm for the new knowledge and continued help
<apeiros> baweaver: whatwhatwhat?
<baweaver> minmax
<this_dude> numbers.split.map(&:to_i).minmax.reverse.join(' ')
<this_dude> he means this apeiros
<this_dude> hehe
<this_dude> okok gtg
<apeiros> bye this_dude
<this_dude> ttyl
<baweaver> map isn't necessary there :D
<baweaver> >> '1 2 3 4 5'.split.minmax(&:to_i).reverse.join(' ')
<ruby[bot]> baweaver: # => no implicit conversion of String into Integer (TypeError) ...check link for more (https://eval.in/1046629)
<baweaver> >> '1 2 3 4 5'.split.minmax_by(&:to_i).reverse.join(' ')
<ruby[bot]> baweaver: # => "5 1" (https://eval.in/1046630)
this_dude has quit [Ping timeout: 252 seconds]
DTZUZO has quit [Ping timeout: 240 seconds]
za1b1tsu has joined #ruby
Puffball has joined #ruby
GodFather has quit [Ping timeout: 265 seconds]
<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
chongtxtx has quit [Ping timeout: 240 seconds]
chongtxtx has joined #ruby
<baweaver> .ruby-version iirc.
dviola has joined #ruby
<apeiros> arooni: passenger can run multiple ruby versions at the same time, yes
Pisuke has joined #ruby
<apeiros> just configure the ruby version per virtual host
<arooni> oh wow; didnt know i could do that;
<arooni> been awhile since i looked at this app lol
<arooni> so if i set a default in my shell (fish) that wont affect the app?
MyMind has quit [Ping timeout: 268 seconds]
<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.
ciro has quit [Quit: WeeChat 2.2]
alfiemax has joined #ruby
chouhoulis has quit [Remote host closed the connection]
alfiemax has quit [Remote host closed the connection]
Puffball has quit [Remote host closed the connection]
desperek has quit [Quit: xoxo]
postmodern has joined #ruby
<baweaver> >> $_=(@_=[*?`..?{][(_=$$/$$)..-_-_]*'')=~/$/;(@__=->_,___,__=''{__<<@_[(___+(@_=~/#{_[$.]}/))%$_];_[$.+=$_/$_]?@__[_,___,__]:__})['ganjah', 4]
<ruby[bot]> baweaver: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
beowuff has quit [Ping timeout: 244 seconds]
eckhardt_ has quit [Quit: Textual IRC Client: www.textualapp.com]
beowuff has joined #ruby
nicesignal has quit [Remote host closed the connection]
nicesignal has joined #ruby
DarthGandalf has quit [Remote host closed the connection]
DarthGandalf has joined #ruby
Caerus has quit [Quit: Leaving]
TJ- has quit [Ping timeout: 256 seconds]
thy0 has quit [Ping timeout: 244 seconds]