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!
fredlinhares has joined #ruby
UserOO7 has quit [Quit: binarynumber.xyz]
maryo has joined #ruby
UserOO7 has joined #ruby
orbyt_ has joined #ruby
clemens3 has quit [Ping timeout: 248 seconds]
djuber has quit [Ping timeout: 256 seconds]
maryo has quit [Ping timeout: 272 seconds]
edwardly has quit [Ping timeout: 248 seconds]
impermanence has quit [Remote host closed the connection]
mikecmpbll has quit [Quit: inabit. zz.]
mroutis has joined #ruby
SCHAPiE has joined #ruby
SCHAPiE has quit [Quit: ZNC - https://znc.in]
patr0clus has quit [Quit: WeeChat 2.1]
kapil___ has quit [Quit: Connection closed for inactivity]
SCHAPiE has joined #ruby
mochiyoda has quit [Remote host closed the connection]
UserOO7 has quit [Remote host closed the connection]
mrush has quit [Quit: leaving]
UserOO7 has joined #ruby
eb0t has joined #ruby
Nicmavr has quit [Read error: Connection reset by peer]
Nicmavr has joined #ruby
herbmillerjr has quit [Excess Flood]
herbmillerjr has joined #ruby
vonfry has joined #ruby
vonfry has quit [Client Quit]
vonfry has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
vonfry1 has joined #ruby
vonfry has quit [Read error: Connection reset by peer]
tristanp has joined #ruby
vonfry has joined #ruby
vonfry1 has quit [Ping timeout: 256 seconds]
jasmith has joined #ruby
za1b1tsu has quit [Ping timeout: 244 seconds]
orbyt_ has joined #ruby
tristanp has quit [Remote host closed the connection]
vonfry1 has joined #ruby
vonfry has quit [Ping timeout: 240 seconds]
oncall-pokemon has joined #ruby
yimao has joined #ruby
mroutis has quit [Remote host closed the connection]
mojtaba has joined #ruby
chouhoulis has joined #ruby
chouhoulis has quit [Ping timeout: 272 seconds]
mroutis has joined #ruby
mozzarella is now known as alex65
alex65 is now known as Guest4585
Guest4585 is now known as mozzarella
SeepingN has joined #ruby
akaiiro has joined #ruby
vonfry1 has quit [Ping timeout: 272 seconds]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SeepingN has quit [Quit: The system is going down for reboot NOW!]
mroutis has quit [Remote host closed the connection]
akaiiro has quit [Ping timeout: 244 seconds]
bmurt has joined #ruby
akaiiro has joined #ruby
tristanp has joined #ruby
eckhardt has joined #ruby
fredlinhares has quit [Quit: WeeChat 1.4]
thy0 has quit [Quit: TTFN]
tristanp has quit [Ping timeout: 240 seconds]
orbyt_ has joined #ruby
ciro has quit [Quit: WeeChat 2.2]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cadillac_ has quit [Quit: I quit]
cadillac_ has joined #ruby
orbyt_ has joined #ruby
dviola has quit [Quit: WeeChat 2.2]
braincrash has quit [Quit: bye bye]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
orbyt_ has quit [Ping timeout: 248 seconds]
AJA4350 has quit [Quit: AJA4350]
braincrash has joined #ruby
herbmillerjr has quit [Excess Flood]
herbmillerjr has joined #ruby
maryo has joined #ruby
maryo has quit [Remote host closed the connection]
akaiiro has quit [Remote host closed the connection]
bmurt has joined #ruby
kapil___ has joined #ruby
<kapil___> I have array of strings. i want to remove concurrent blank strings to one string element. how to do it?
pskosinski has quit [Ping timeout: 240 seconds]
pskosinski has joined #ruby
t0xik has quit [Quit: Connection closed for inactivity]
oncall-pokemon has quit [Quit: Connection closed for inactivity]
orbyt_ has joined #ruby
mojtaba has quit [Quit: Leaving.]
aniarya82 has joined #ruby
<havenwood> >> ['hi', ' ', 'kapil___', "\n", ''].chunk { |s| s.match? /\A\s*\z/ }.map(&:last).each_slice(2).map(&:join)
<ruby[bot]> havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<havenwood> #=> ["hi ", "kapil___\n"]
<havenwood> kapil___: Is it Rails? You could: chunk(&:blank?)
<havenwood> kapil___: Though #blank? is implemented with #match? these days. :-)
tty has quit [Ping timeout: 240 seconds]
tty has joined #ruby
tty has quit [Client Quit]
tty has joined #ruby
Freshnuts has joined #ruby
tdy has quit [Ping timeout: 272 seconds]
mojtaba has joined #ruby
_whitelogger has joined #ruby
tpendragon has quit [Remote host closed the connection]
giraffe has quit [Remote host closed the connection]
vonfry has joined #ruby
cadillac_ has quit [Ping timeout: 256 seconds]
cadillac_ has joined #ruby
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tpendragon has joined #ruby
mojtaba has quit [Remote host closed the connection]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alex`` has joined #ruby
reber has joined #ruby
alex`` has quit [Quit: WeeChat 2.2]
kapil___ has quit [Quit: Connection closed for inactivity]
quazimodo has quit [Ping timeout: 240 seconds]
mojtaba has joined #ruby
mike11 has joined #ruby
alex`` has joined #ruby
drbrain has quit [Quit: Goodbye]
mrush has joined #ruby
mojtaba has quit [Ping timeout: 256 seconds]
drbrain has joined #ruby
alehander42_ has joined #ruby
<alehander42_> how to use oop effectively? can i use more fp approach with ruby
mojtaba has joined #ruby
za1b1tsu has joined #ruby
za1b1tsu has quit [Ping timeout: 272 seconds]
vonfry has quit [Quit: WeeChat 2.2]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
pskosinski has quit [Ping timeout: 240 seconds]
User458764 has joined #ruby
pskosinski has joined #ruby
_whitelogger has joined #ruby
<mike11> is there any way to achieve a control flow like this https://github.com/micjabbour/pronto-clang_tidy/blob/issue-3/lib/pronto/clang_tidy_runner.rb#L94-L104 in a pure functional way? (i.e. using map, reduce, ...)
<mike11> basically, I am doing a map, but if some condition is met on the current object, I want to pass it to the last added object instead of mapping it to something else...
User458764 has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
mydog2 has quit [Ping timeout: 256 seconds]
sameerynho has joined #ruby
apparition has joined #ruby
quazimodo has joined #ruby
kapil___ has joined #ruby
<kapil___> havenwood: thanks
Rootsudo has joined #ruby
quazimodo has quit [Ping timeout: 272 seconds]
BTRE has quit [Remote host closed the connection]
BTRE has joined #ruby
Freshnuts has quit [Quit: Leaving]
User458764 has joined #ruby
mojtaba has quit [Quit: Leaving.]
dhollin has joined #ruby
dhollin3 has quit [Ping timeout: 244 seconds]
clemens3 has joined #ruby
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ferhaty has joined #ruby
Dbugger has joined #ruby
apparition has quit [Quit: Bye]
mike11 has quit [Quit: Leaving.]
alehander42_ has quit [Remote host closed the connection]
User458764 has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
gheegh has joined #ruby
User458764 has joined #ruby
howdoi has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
alex`` has quit [Quit: WeeChat 2.2]
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
mikecmpbll has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
User458764 has joined #ruby
User458764 has quit [Client Quit]
<apeiros> !fixcon User458764
aniarya82 has quit [Quit: My MacBook Air has gone to sleep. ZZZzzz…]
kapil___ has quit [Quit: Connection closed for inactivity]
nowhereman_ has quit [Remote host closed the connection]
ferhaty has quit [Quit: ferhaty]
nowhereman_ has joined #ruby
ferhaty has joined #ruby
AJA4350 has joined #ruby
wildermind has joined #ruby
ferhaty has quit [Quit: ferhaty]
alex`` has joined #ruby
plutes has quit [Ping timeout: 244 seconds]
alex`` has quit [Client Quit]
ciro has joined #ruby
ArahaelPi has quit [Quit: 17]
arahael1 has joined #ruby
Nicmavr has quit [Read error: Connection reset by peer]
Nicmavr has joined #ruby
gigetoo has joined #ruby
kapil___ has joined #ruby
arahael1 is now known as ArahaelPi
nowhereman_ has quit [Remote host closed the connection]
nowhereman_ has joined #ruby
dellavg has joined #ruby
Emmanuel_Chanel has joined #ruby
nowhereman_ has quit [Ping timeout: 256 seconds]
sylario has joined #ruby
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dellavg has quit [Ping timeout: 260 seconds]
gheegh has joined #ruby
dellavg has joined #ruby
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
savolla has joined #ruby
mojtaba has joined #ruby
banisterfiend has joined #ruby
GodFather has joined #ruby
banisterfiend has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
thy0 has joined #ruby
dviola has joined #ruby
DLSteve has joined #ruby
Pip has joined #ruby
GodFather has quit [Ping timeout: 265 seconds]
GodFather has joined #ruby
kevinsjoberg has joined #ruby
MyMind has quit [Ping timeout: 240 seconds]
Rootsudo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Rootsudo has joined #ruby
Rootsudo has quit [Client Quit]
Rootsudo has joined #ruby
Rootsudo has quit [Client Quit]
Rootsudo has joined #ruby
Rootsudo has quit [Client Quit]
Rootsudo has joined #ruby
Rootsudo has quit [Client Quit]
Rootsudo has joined #ruby
Rootsudo has quit [Client Quit]
banisterfiend has joined #ruby
aniarya82 has joined #ruby
dviola has quit [Quit: WeeChat 2.2]
banisterfiend has quit [Ping timeout: 272 seconds]
<havenwood> mike1, oh - they left
<havenwood> Anyways, if they read the logs - make Offence#initialize take notes so you don't have to shovel them on, then:
<havenwood> diags.chunk { |diag| diag.level == :note }.map(&:last).map { |offences| Offence.new *offences }
dviola has joined #ruby
Pip has quit [Ping timeout: 268 seconds]
improv42 has joined #ruby
kapil___ has quit [Quit: Connection closed for inactivity]
nuck has quit [Quit: Connection closed for inactivity]
improv42 has quit [Remote host closed the connection]
ciro has quit [Ping timeout: 272 seconds]
improv42 has joined #ruby
mojtaba has quit [Quit: Leaving.]
fmcgeough has joined #ruby
yorickpeterse has joined #ruby
DLSteve has quit [Quit: All rise, the honorable DLSteve has left the channel.]
chouhoulis has joined #ruby
duderonomy has joined #ruby
chouhoulis has quit [Ping timeout: 260 seconds]
duderonomy has quit [Ping timeout: 240 seconds]
yimao has quit [Quit: leaving]
sagax has joined #ruby
<sagax> hi all!
<sagax> how to write this shortly?
<sagax> or better
<apeiros> env = {"production" => "production", "development" => "development", "test" => "test"}.fetch(ENV["NODE_ENV"], "development")
<apeiros> and put the hash into a constant instead of inline
<apeiros> IMO you should use {nil => "development"} and no default in the fetch, though. that way it raises if it's set to an invalid value.
<sagax> wow
<sagax> apeiros: thanks
<sagax> it's great
nowhereman_ has joined #ruby
mike11 has joined #ruby
<canton7> (btw, try and avoid unless...else - it tends to do people's heads in
<canton7> sagax, another way of writing that would be `env = "development" if !ENV.has_key?("NODE_ENV") || !["production", "development", "test"].include?(ENV["NODE_ENV"])`
<apeiros> <topper mode> try unless elsif! supergreat :D
<havenwood> sagax: Or: env = ENV.fetch 'NODE_ENV', 'development'
<havenwood> sagax: Then do your validity check separately: env = 'development' unless %[production development test].include? env
<havenwood> I meant %w[
<havenwood> sagax: I'd vote just: env = ENV.fetch 'NODE_ENV', 'development'
<havenwood> If someone sets ENV to something else, like "prodmuction" - I'd rather fail than have it silently be "development".
ciro has joined #ruby
fmcgeough has quit [Quit: fmcgeough]
yorickpeterse has quit [Quit: WeeChat 2.2]
ciro has quit [Ping timeout: 256 seconds]
mojtaba has joined #ruby
dellavg has quit [Remote host closed the connection]
DTZUZU has quit [Quit: WeeChat 1.9]
Dbugger has quit [Ping timeout: 265 seconds]
dellavg has joined #ruby
<sagax> thanks all!
scientes has quit [Disconnected by services]
duderonomy has joined #ruby
mroutis has joined #ruby
rippa has joined #ruby
DTZUZU has joined #ruby
improv42 has quit []
<mike11> hello all :)
<mike11> I am looking for a way to express the following operation in a functional manner (i.e. using map, reduce, ...etc) http://rextester.com/YKA63660
<Zarthus> can you describe the goal
<mike11> Basically, I am mapping each element to an array that contains it. Except when the element is less than 10, it is appended to the last element's array
<Zarthus> but your desired output is [[20, 2, 3], [30, 3, 4], [40, 4, 5]]?
<mike11> Zarthus: exactly, and I am guaranteed that the input array's first element is not less than 10
psychicist__ has joined #ruby
<Zarthus> ah, i see now, L6 adds a new array
<mike11> Zarthus: I have committed similar code into production yesterday, but I feel about it :p
<mike11> feel bad*
* Zarthus shrugs
ciro has joined #ruby
<canton7> Mike11, Enumerable#slice_before
<mroutis> it's not that bad, Mike11, being functional not translates into good-quality-handcrafted-by-artisan code
<mroutis> however, you could use each_slice.to_a
<mroutis> >> [20, 2, 3, 30, 3, 4, 40, 4, 5].each_slice.to_a
<ruby[bot]> mroutis: # => wrong number of arguments (given 0, expected 1) (ArgumentError) ...check link for more (https://eval.in/1046814)
<mroutis> >> [20, 2, 3, 30, 3, 4, 40, 4, 5].each_slice(3).to_a
<ruby[bot]> mroutis: # => [[20, 2, 3], [30, 3, 4], [40, 4, 5]] (https://eval.in/1046815)
<canton7> mroutis, try an input of [20, 2, 30, 3, 4, 40, 4, 5, 6] ;)
cadillac_ has quit [Ping timeout: 272 seconds]
<mroutis> >> [20, 2, 3, 30, 3, 4, 40, 4, 5, 6].each_slice(3).to_a
<ruby[bot]> mroutis: # => [[20, 2, 3], [30, 3, 4], [40, 4, 5], [6]] (https://eval.in/1046816)
<canton7> that's not what I said...
<mike11> mroutis: I am not guaranteed to have 3-sized slices
<canton7> >> [20, 2, 30, 3, 4, 40, 4, 5, 6].slice_before{ |x| x < 10 }.to_a
<ruby[bot]> canton7: # => [[20], [2, 30], [3], [4, 40], [4], [5], [6]] (https://eval.in/1046817)
<canton7> bleh
<canton7> >> [20, 2, 30, 3, 4, 40, 4, 5, 6].slice_before{ |x| x > 10 }.to_a
<ruby[bot]> canton7: # => [[20, 2], [30, 3, 4], [40, 4, 5, 6]] (https://eval.in/1046818)
savolla has quit [Ping timeout: 240 seconds]
<mike11> canton7: I think that this should work, thank you very much :)
cadillac_ has joined #ruby
<mroutis> I just completely misunderstood the problem, lol; canton7, that was a pretty clean solution
mike11 has quit [Quit: Leaving.]
mojtaba has quit [Quit: Leaving.]
tdy has joined #ruby
maryo has joined #ruby
maryo has quit [Ping timeout: 244 seconds]
conta has joined #ruby
nielsk has quit [Quit: So Long, and Thanks for All the Fish]
nielsk has joined #ruby
conta has quit [Client Quit]
doubledup has quit [Remote host closed the connection]
Fusselgesicht has joined #ruby
nowhere_man has joined #ruby
nowhereman_ has quit [Ping timeout: 256 seconds]
orbyt_ has joined #ruby
<sagax> Rake can find rakefile.rb ?
<mroutis> what do you mean, sagax ?
<sagax> rake file can be "Rake.rb", "rakefile.rb" or other
<mroutis> No, actually the search path is the following: No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
<sagax> and i need Rake.load_rakefile without write name
<sagax> just automation
<mroutis> you can specify the rakefile with the `-f` flag
<mroutis> rake -f unconventional_name.rb
<sagax> no
AJA4350 has quit [Remote host closed the connection]
<sagax> i don't need it
<sagax> i don't need rake
<sagax> and don't need -f
<sagax> thanks
<mroutis> yep
AJA4350 has joined #ruby
ByronJohnson has quit [Ping timeout: 240 seconds]
ByronJohnson has joined #ruby
kapil___ has joined #ruby
<sagax> when i do this -- app = Rake::Application.new; app.load_rakefile; app.tasks
<sagax> tasks = []
<sagax> but it's not true, rakefile have tasks
<mroutis> sagax, try with Rake::Task['yourtask'].invoke
<sagax> if i do Rake.load_rakefile(namerakefile) i have tasks in Rake::Task.tasks
<sagax> but i need load_rakefile without specifiec rake file name
<sagax> mroutis: without "load_rakefile" you way don't work
<mroutis> normally, it would work like that, sagax, you don't need to specify the "namerakefile"
<mroutis> indeed, you need to load_rakefile
<sagax> no, i want not write name
<mroutis> you don't need to
<sagax> Rake must be find rakefile in self
<mroutis> just `Rake.load_rakefile`
<mroutis> without name
Jacky has quit [Quit: ZNC 1.6.6 - http://znc.in]
<sagax> in app.load_rakefile - not require rakefilename
<sagax> it's can find rakefile
<sagax> but not loading tasks
jalcine has joined #ruby
<mroutis> try this, dude
<sagax> this don't work
<mroutis> download those files, and run `ruby test.rb`
<mroutis> you'll see that is loading the tasks without specifying explicitly the name of the rakefile
<sagax> i don't need download this
<sagax> it's strange behavior
<sagax> because app.tasks must be have "tasks"
mike11 has joined #ruby
Fusselgesicht has quit [Quit: leaving]
wildermind has quit [Quit: Connection closed for inactivity]
mike11 has quit [Quit: Leaving.]
jalcine has quit [Quit: ZNC 1.6.6 - http://znc.in]
jalcine has joined #ruby
dinfuehr has quit [Ping timeout: 248 seconds]
levifig has joined #ruby
alfiemax has joined #ruby
dinfuehr has joined #ruby
alfiemax_ has joined #ruby
alfiemax has quit [Ping timeout: 272 seconds]
ellcs has joined #ruby
mroutis has quit [Ping timeout: 272 seconds]
mroutis has joined #ruby
ellcs has quit [Ping timeout: 240 seconds]
mojtaba has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dellavg has quit [Ping timeout: 240 seconds]
ellcs has joined #ruby
mroutis has quit [Ping timeout: 244 seconds]
ShekharReddy has quit [Quit: Connection closed for inactivity]
ellcs has quit [Ping timeout: 265 seconds]
herbmillerjr has quit [Quit: Konversation terminated!]
mojtaba has quit [Quit: Leaving.]
ur5us has joined #ruby
mroutis has joined #ruby
aphprentice_ has joined #ruby
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
dionysus69 has joined #ruby
kapil___ has quit [Quit: Connection closed for inactivity]
dionysus69 has quit [Ping timeout: 244 seconds]
GodFather has quit [Ping timeout: 240 seconds]
wildermind has joined #ruby
aniarya82 has quit [Quit: My MacBook Air has gone to sleep. ZZZzzz…]
this_dude has joined #ruby
fmcgeough has joined #ruby
<this_dude> ok guys
<this_dude> im gonna do my last attempt for this exam
<this_dude> who's online
<baweaver> who's not?
<this_dude> hehe
<this_dude> ok here goes
<this_dude> actually let me do a couple practice problems to warm up
<this_dude> omg so i found a group here looking for a ruby developer
<this_dude> how do i make a coding resume??
<this_dude> or portfolio
clemens3 has quit [Ping timeout: 244 seconds]
<Radar> GOOD MORNING
<Radar> this_dude: github.com
<Radar> ?next
<ruby[bot]> Radar: I don't know anything about next
<baweaver> ohai Radar
<Radar> Yes it is I, the Radar.
fmcgeough has quit [Quit: fmcgeough]
<Radar> this_dude: protip: if you're going to make a coding portfolio for Ruby, you should probably stop avoiding using blocks / procs / enumerable methods.
<havenwood> this_dude: See github.com/ONE_OF_OUR_SCREEN_NAMES
<Radar> this_dude: because if I was reviewing such a coding portfolio I would reject it because it is demonstrably bad Ruby.
<this_dude> hehehe
<Radar> Source: I am about to start reviewing a bunch of junior coding portfolios in a few weeks, with the aim of hiring 6 new junior Rubyists.
<this_dude> gotta start somewhere i guess
<sagax> why blocks and procs - it's bad?
<Radar> Source: I also reviewed ~80 junior coding tests before and I have Mad Opinions™ about what Good Junior Ruby Code™ looks like.
<Radar> sagax: he's writing .each loops using while instead.
<Radar> i = 0; while i < things.length; things[i]; i += 1; end
<Radar> instead of: things.each do |thing|; thing; end
<Radar> yeah great you know how to do it the long way but if people are interviewing you based on that they're not interviewing you for your Ruby skills. They're interviewing more like for your obfuscation skills.
<sagax> hm, it's bad, yes
<sagax> ruby like as C ;D
<this_dude> its cause c was the first language i learned hah
<Radar> Yeah. It's not the _worst_ Ruby code, but it's not _quite_ Ruby as intended.
<this_dude> hard to get away from old habbits
reber has quit [Remote host closed the connection]
<havenwood> old hobbits too
<Radar> (The worst Ruby code I used simultaneously ignored / over used the space bar and littered global variables throughout)
<sagax> Frodo with ring
<Radar> I reviewed used*
<this_dude> hmm
<this_dude> when removing the lowest number in an array
<this_dude> can i not just.. arr.min.shift?
<this_dude> oh wait no
<this_dude> hold on
<this_dude> arr.min.delete?
<baweaver> What does min return?
<this_dude> the lowest integer in the array
<baweaver> yep, and do integers know how to delete?
<this_dude> oh shoot no
<this_dude> ok gonna go to my integer method dictionary brb
<this_dude> wtf
<this_dude> cant find anything
<baweaver> yep. Now why would a number know how to delete something from an array?
<baweaver> An array knows how to delete something from an array.
<this_dude> arr.digits.map { |n| n.min.delete }
<this_dude> ?
<baweaver> If you're calling digits, you're working on a number
<baweaver> so calling it arr is odd.
<baweaver> What does map do?
<this_dude> you're right
<this_dude> stores the values in an array to a hash
<this_dude> so take out the .digits
<baweaver> nope
<baweaver> Look it up
blood has joined #ruby
mikecmpbll has quit [Quit: inabit. zz.]
quazimodo has joined #ruby
<this_dude> what am i looking up exactly
<baweaver> map.
<blood> given the following xml using Nokogiri : https://gist.github.com/bloodmc/ecc618f9b047162c4c21c3ed5cc8daf8, Why wouldn't the following code return any results ? https://dpaste.de/wLg1
agent_white has joined #ruby
<Radar> blood: what's the xpath you're passing there?
<baweaver> Also that exists method is odd.
<blood> woops /web-app/filter-mapping[filter-name='psfilter']
<Radar> ta. I reckon you're missing an XML namespace from that xpath.
<this_dude> oh wait i figured it out
<baweaver> def exists(xpath) @document.xpath(xpath).empty? end
<this_dude> numbers.delete(numbers.min)
<baweaver> that already returns a boolean result
<Radar> baweaver: yeah the method is longer than it needs to be. Guessing because of the Puppet.debug line
<blood> baweaver: i was printing out debug
<baweaver> def exists(xpath) @document.xpath(xpath).empty?.tap { Puppet.debug ... } end
<Radar> [09:20:49] <Radar>ta. I reckon you're missing an XML namespace from that xpath.
<this_dude> ooo now i have a problem
<Radar> blood: ^
tdy has quit [Ping timeout: 260 seconds]
<blood> sure there are a million ways to write it, thats not the question here
* Radar taps mic, asks "is this thing on?"
<blood> ah
<this_dude> if theres two of the same minimum number in the array it only wants me to delete one of them
<baweaver> this_dude: then that's an edge case you need to answer.
<baweaver> Though `sort` may be interesting too.
<this_dude> a what
<Radar> this_dude: edge case
<this_dude> *googles furiously*
<baweaver> How do you handle odd cases like that? That's an edge case.
<Radar> blood: xml.xpath('//web:display-name', 'web' => "http://java.sun.com/xml/ns/javaee")
<this_dude> oh "extreme minimums or maximums"
<Radar> blood: where that URL comes from <web-app>'s xmlns attribute
<blood> Radar: how would i ignore namespace?
<Radar> blood: xml.remove_namespaces!
<blood> ah so i add that when i create the XML doc right?
<Radar> blood: yeah
<blood> thanks, let me try
<Radar> xml = Nokogiri::XML.parse(File.read('web.xml'))
<Radar> xml.remove_namespaces!
<this_dude> hmm
<this_dude> what method can i use
<this_dude> .sort.size.shift
<Radar> this_dude: how would you sort the array in numerical order?
<this_dude> but idk if size is a thinkg
<this_dude> thing*
<Radar> this_dude: how would you sort the array in numerical order?
<Radar> [4,3,2,5,1].<what>
<Radar> blood: did that work?
<this_dude> wait
<this_dude> dont tell me
<this_dude> im trying to remember
<this_dude> i have it
<Radar> this_dude: enter is not a spacebar
<this_dude> srry
<this_dude> habit
<Radar> and you did it again
orbyt_ has joined #ruby
<this_dude> .sort_by! { |n| size }
<this_dude> right?
<Radar> this_dude: try it. Did it result in an array of [1, 2, 3, 4, 5]?
<Radar> >> [4, 3, 2, 5, 1].sort_by! { |n| size }
<ruby[bot]> Radar: # => undefined local variable or method `size' for main:Object (NameError) ...check link for more (https://eval.in/1046877)
<Radar> hm nope
<this_dude> >> [4, 3, 2, 5, 1].sort_by! { |n| n.size }
<ruby[bot]> this_dude: # => [4, 3, 2, 5, 1] (https://eval.in/1046878)
<this_dude> shoot
<Radar> this_dude: y u no google
<Radar> your keywords: ruby, sort, array
<this_dude> i have the documents already open
<this_dude> im looking
<Radar> clearly you're not reading them
<blood> Radar: yup that worked thanks
<this_dude> >> [4, 3, 2, 5, 1].sort_by! { |n| n.self }
<Radar> this_dude: is there any other method that starts with "sort" in the Array class?
<ruby[bot]> this_dude: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<blood> was scratching my head not realizing it was the namespace all this time
<blood> =) thanks again
<Radar> blood: no problem :)
<Radar> I like that JSON does not have this fault.
<this_dude> >> [4, 3, 2, 5, 1].sort { |a,b| a<=>b }
<ruby[bot]> this_dude: # => [1, 2, 3, 4, 5] (https://eval.in/1046879)
<this_dude> ah
nowhere_man has quit [Ping timeout: 256 seconds]
<blood> Radar: do you prefer Nokogiri over REXML?
<Radar> blood: yes
<Radar> this_dude: are you intentionally being obtuse
<Radar> just wondering
<havenwood> >> [].methods.grep /sort/ # this_dude
<ruby[bot]> havenwood: # => [:sort, :sort_by!, :sort!, :sort_by] (https://eval.in/1046884)
<Radar> Because if you found sort { |a, b| <=> b } you probably found the shorter version too
<blood> ok great, I'm currently migrating xml_fragment puppet module to Nokogiri so I can also use it for HTML. Just making sure I chose right =)
<this_dude> no im not being intentionally obtuse
<this_dude> >> [4, 3, 2, 5, 1].sort
<ruby[bot]> this_dude: # => [1, 2, 3, 4, 5] (https://eval.in/1046885)
<this_dude> oh smh
* Radar claps
<Radar> yay
<Radar> this_dude: ok, now how do you remove the first element in array?
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<this_dude> numbers.delete(numbers.sort[0])
kapil___ has joined #ruby
<Radar> numbers = [1,1,2,3]; numbers.delete(numbers.sort[0])
<Radar> >> numbers = [1,1,2,3]; numbers.delete(numbers.sort[0])
<ruby[bot]> Radar: # => 1 (https://eval.in/1046886)
<Radar> >> numbers = [1,1,2,3]; numbers.delete(numbers.sort[0]); numbers
<ruby[bot]> Radar: # => [2, 3] (https://eval.in/1046887)
<Radar> this_dude: not quite. It deletes both 1s.
<this_dude> i see that
<this_dude> numbers.grep(numbers.sort[0])
<Radar> this_dude: what does google say?
<Radar> I plugged my exact question into Google and it tells me the answer "how do you remove the first element in array in Ruby?" -> boom first reuslt
duderonomy has joined #ruby
<this_dude> oh
<this_dude> numbers.delete_at[0](numbers.sort)
<Radar> ok yeah you're intentionally being obtuse. I need a break bye.
<this_dude> im NOT
<Radar> I asked "what does google say?" to try to coax you towards the right action and you don't take it
<Radar> it is intensely infuriating
<Radar> you do this time after time after time
<this_dude> im checking the doc seriously.
<Radar> did I just say check the documentation or did I just say check google?
<this_dude> ok brb
<Radar> Thank you.
blood has quit [Remote host closed the connection]
<this_dude> ohhhh i thought it was shift thats where i was wrong
<this_dude> i had .pop and .shift confused
blood has joined #ruby
<this_dude> wait i am right pop is from the end
<this_dude> google said pop
duderonomy has quit [Ping timeout: 244 seconds]
<this_dude> UGH this is frustrating bc i know the answer is gonna be something so simple
<Radar> [09:37:51] <Radar>I plugged my exact question into Google and it tells me the answer "how do you remove the first element in array in Ruby?" -> boom first reuslt
<Radar> Literally. First link. First answer on the question.
<this_dude> .drop
<this_dude> never heard of that...cool
nowhere_man has joined #ruby
<Radar> drop will return the array without n number of elements, but shift will modify the array to remove the first element
<Radar> >> a = [1,2,3,4,5].drop(2); a
<ruby[bot]> Radar: # => [3, 4, 5] (https://eval.in/1046891)
<Radar> um
<Radar> Am I _wrong_?
<this_dude> but numbers.shift(numbers.sort) doesnt work
<Radar> chain the methods: numbers.sort.shift
<Radar> OK, so it looks like I was wrong. drop modifies the array too. I thought it didn't.
<this_dude> how do you "unsort"
<Radar> Oh no, I am wrong yet again...
<this_dude> cause i need to return the array in the original order minus the min value
<Radar> >> a = [1,2,3,4,5]; a.drop(2); a
<ruby[bot]> Radar: # => [1, 2, 3, 4, 5] (https://eval.in/1046892)
<Radar> Because my first example assigned a to the result of drop
<Radar> this_dude: show me the question again please
<Radar> Cool.
tdy has joined #ruby
<Radar> Well that's harder then.
<this_dude> ):
<Radar> Ok, so we've got half the problem figured out. We know how to get the lowest value... well, one of the ways. But we need to not mutate the original array.
<this_dude> yeah...
<this_dude> next hint pls?
<Radar> >> a = [5,4,1,3,2]; a.sort.first
<ruby[bot]> Radar: # => 1 (https://eval.in/1046893)
<Radar> That will return you the lowest number without mutating the array.
<Radar> Then your next task is to find the INDEX of the lowest number in that array.
<this_dude> ok
* baweaver is curious now
<Radar> So you have the lowest number, you just need to find the index. With that index, then you can delete the object from the array.
<Radar> Steps are: 1) find the lowest number [CHECK] 2) find one spot in the array where that number occurs [IN PROGRESS] 3) delete only the element at that location
<this_dude> numbers.delete_at(numbers.index(numbers.sort[0]))
<this_dude> ?
<havenwood> >> Array.instance_methods.select { |name| a = [:a, :b]; a.public_send(name) rescue nil; a == [:b] }
<this_dude> GOT IT
<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> YAAY ME
<havenwood> #=> [:shift]
<this_dude> no need for shift
<this_dude> it works for all the minitests
<havenwood> this_dude: I haven't looked at the problem. Just showing a dirty way to ask Ruby what it's method is that can do that thing. That's pretty easy when methods don't take arguments or blocks.
<havenwood> If they take args, kwargs or blocks - you have to start fuzzing. ;-)
<this_dude> oh
<havenwood> this_dude: Remove the smallest numbers from an Array of numbers?
<this_dude> yeah
<this_dude> well no
<this_dude> remove only the first instance of the smallest number of an array of numbers
<havenwood> this_dude: And preserve the order?
<this_dude> im gonna go resetup at a cowork space...be back in like 30
<this_dude> correct
<this_dude> ill check the chat log when i get back so feel free to comment while im afk :D