Axy has quit [Read error: Connection reset by peer]
Mia has joined #ruby
Netto has joined #ruby
vondruch_ has joined #ruby
vondruch_ has left #ruby [#ruby]
vondruch has quit [Ping timeout: 265 seconds]
pwl has joined #ruby
gigetoo has quit [Ping timeout: 260 seconds]
mohsen_in has joined #ruby
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ur5us has quit [Ping timeout: 264 seconds]
duderonomy has joined #ruby
tempate has joined #ruby
<tempate>
Hello there. I just wrote my very first 'Hello World' in Ruby. I'm going to try to code AdventOfCode in it this year, as a learning experience. I was wondering: what's the correct way of looping through array elements by index starting at a given one?
Nahra has joined #ruby
<leftylink>
as a first step, note that it is possible to get a subarray of an array by passing in a range to its index operator
<leftylink>
then, one can iterate that array. alternatively, if one really really hates creating that new subarray, I guess you can just do (2...whatever).each { |i| x = array[i]; do_stuff_with(x) }, but advent of code is not one of the contexts where this really matters
<tempate>
Alright, I'm going to try my hand at it
<tempate>
Thanksd
pwl has quit [Read error: Connection reset by peer]
postmodern has quit [Quit: Leaving]
<leftylink>
hmm, based on context I might need to add something, which is that one should look at Array#each for iteration. and generally the things in Enumerable
<leftylink>
though maybe the fact that the question "so how do you iterate an array at all" wasn't asked means that it wasn't actually necessary for me to add that
<leftylink>
I guess I overshared
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<tempate>
I was thinking of iterating with each_with_index to get both the index and the element, no?
<leftylink>
oh sure
<tempate>
What should I go for: brackets or do-end?
vondruch_ has joined #ruby
vondruch_ is now known as vondruch
<leftylink>
pick one strategy and use it consistently. strategy A: use brackets if it's a one-liner and use do-end if it's a multi-liner. strategy B: use brackets if the value of the block is meaningful, use do-end if it's meaningless (e.g. the block was only used for its side effect). strategy C: always brackets
<leftylink>
I don't think anyone ever advocated for always do-end so I left that one out
<tempate>
Alright, great
<leftylink>
er, s/value of the block/value of the method that used the block/
<leftylink>
so that would imply using {} for map but do/end for each
<leftylink>
I think it was ruby 2.5 that introduced endless range, so if not on a version that supports endless range, will have to use start..-1 instead of just start.. . but without more specifics about the error I couldn't say more
<leftylink>
on, 2.6 for endless range
<leftylink>
2.7 for beginless range
<tempate>
I'm on 2.5 apparently
<tempate>
I guess I should update
<leftylink>
well, if update is not possible adding the -1 is fine, really
<leftylink>
though I really like the block arg that was added to Enumerable#to_h in 2.6
<tempate>
Alright
<tempate>
Thanks for the help
cloud69 has joined #ruby
someone002 has joined #ruby
<leftylink>
yup
royo25 has joined #ruby
royo25 has quit [Client Quit]
someone002 has quit [Client Quit]
Azure|dc has joined #ruby
roger_rabbit has joined #ruby
Azure has quit [Ping timeout: 240 seconds]
Nahra has quit [Quit: leaving]
sphex has joined #ruby
akem has joined #ruby
royo25 has joined #ruby
royo25 has quit [Client Quit]
royo25 has joined #ruby
royo25 has quit [Quit: Bye]
cliluw has quit [Read error: Connection reset by peer]
royo25 has joined #ruby
akem has quit [Ping timeout: 246 seconds]
Netto has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<chewb>
make: *** No rule to make target '/C/tools/ruby27/include/ruby-2.7.0/ruby.h', needed by 'adj_matrix.o'. Stop.
<chewb>
i cant install sonargraph
<chewb>
i mean solargraph
fercell has joined #ruby
<isene>
In RTFM (https://github.com/isene/RTFM) I am looping and halting for user to press a key. But - I want to keep the loop running (in case an external program changes files on the system, I want them to also change in RTFM) - how can I best do this? I tried fumbling around with putting the "getkey" into a thread, but had no luck with that approach and thought it wiser to ask here.
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<adam12>
cek: No great answer, but my guess is you will maybe need to use Open3 to get individual IO objects, instead of the multiplexed one from IO.popen.
<adam12>
cek: I can't really say for sure unless I had an example of what you were doing. I don't normally reopen.
<cek>
nah, that won't help. it appears you can't redirect pipes as you would do with fds
code_zombie has joined #ruby
<cek>
unless I'm missing something. Anyway, made a fork and plumbing inside it.
Mikaela has left #ruby [#ruby]
<adam12>
isene: Could you use IO.select([$stdin], [], [], 1) in the loop? or maybe even $stdin.ready?
akem has quit [Remote host closed the connection]
akem has joined #ruby
<adam12>
Oh nm, $stdin.ready? isn't a thing.. Hmm.
<cek>
I'm also interested why can't `Process.wait` reap my zombie `popen` process... says Errno::ECHILD
<adam12>
STDIN is missing a bunch of IO methods. I wonder why...
kurko_ has joined #ruby
orbyt_ has joined #ruby
fippy__ has joined #ruby
fippy_ has quit [Ping timeout: 260 seconds]
htmnc has joined #ruby
<htmnc>
ruby's C code is so clean
<summerisle>
ruby in general seems to have an ecosystem of clean looking code
<htmnc>
yeah, it's nice
<htmnc>
also the copious amounts of documentation within its source
fippy__ has quit [Ping timeout: 256 seconds]
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<isene>
adam12: hmm?
<isene>
If I could only loosen it out in a thread that waits for user to hit a key while the loop is looping, but without the loop massively creating the threads...
hassox has joined #ruby
TCZ has joined #ruby
Swyper has joined #ruby
Swyper has quit [Remote host closed the connection]
cloud69 has quit [Quit: Connection closed for inactivity]
fercell has quit [Ping timeout: 256 seconds]
r29v has joined #ruby
kurko_ has quit [Ping timeout: 256 seconds]
r29v has quit [Quit: r29v]
kurko_ has joined #ruby
banisterfiend has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<isene>
Thread.new { main_getkey; @thread = false } # Get key from user
<isene>
else
<isene>
10000.times {}
<isene>
end
<isene>
Without the 10000.times {}, it flickers a lot
<isene>
So, I need a better way...
akem has joined #ruby
akem has quit [Max SendQ exceeded]
akem has joined #ruby
deadbee has quit [Quit: WeeChat 2.9]
al2o3-cr has joined #ruby
<isene>
Now, if I set it to 100000.times {} it actually looks smooth (and I cannot use sleep as it hangs the program, naturally)
<isene>
It's ugly as heck, but it does seem to work, though
shaman42 has quit [Ping timeout: 256 seconds]
hiroaki has joined #ruby
<isene>
On another note - the Astropanel now has a starmap showing in the terminal with the option to refresh it at the selected time to see how the sky looks like at that time: http://isene.com/x/2020-12-01-224535_1915x1039_scrot.png
<adam12>
isene: What's the loop? `loop do; end`? or something through Enumerable.
Azure|dc has quit [Read error: Connection reset by peer]
Azure has joined #ruby
dfucci has quit [Ping timeout: 256 seconds]
crankharder has quit [Ping timeout: 260 seconds]
Iarfen has quit [Ping timeout: 272 seconds]
crankharder has joined #ruby
crankharder has quit [Ping timeout: 256 seconds]
shaman42 has joined #ruby
Iarfen has joined #ruby
cek has quit [Quit: Connection closed for inactivity]
Iarfen has quit [Ping timeout: 272 seconds]
ellcs has joined #ruby
TCZ has quit [Remote host closed the connection]
dfucci has joined #ruby
Iarfen has joined #ruby
r34lp0w3r[m] has joined #ruby
mwlang has joined #ruby
<mwlang>
Is there a simple way to detect with a Ruby core class has been monkey patched?
<al2o3-cr>
using pry, you could use show-method -a cls/mod
<al2o3-cr>
you'd need to install pry-doc though
weaksauce has joined #ruby
<mwlang>
pry is actually how I managed to find it.
<mwlang>
basically, I ended up with an infinite recursion issue because airbrake is patching Net::HTTP’s #request method.
ellcs has quit [Ping timeout: 240 seconds]
<al2o3-cr>
mwlang: barring that, there really isn't a simple way of knowing.
dfucci has quit [Ping timeout: 256 seconds]
<mwlang>
ok, I’ll look at how pry-doc can display that info. Appreciate the pointer there.
<al2o3-cr>
mwlang: sure, np.
mokha has quit [Quit: .]
TCZ has joined #ruby
dfucci has joined #ruby
<mwlang>
Looks like this does it: Object.instance_method(:method).bind(Net::HTTP.allocate).call("request").source_location
<mwlang>
It’ll return file name and line number and that’s good enough to detect if it’s been monkeyed with.
dfucci has quit [Ping timeout: 246 seconds]
dfucci has joined #ruby
<al2o3-cr>
mwlang: pretty much :) btw, if using a more recent ruby you can call it like Object.instance_method(:meth).bind_call(Net::HTTP.allocate, 'request').source_location
Technodrome has joined #ruby
<mwlang>
how recent? 2.6.6 seems not to like that.
<al2o3-cr>
mwlang: :( 2.7+
<al2o3-cr>
i thought it was earlier
dfucci has quit [Ping timeout: 264 seconds]
<mwlang>
Ah. Well, it was worth a shot.
<al2o3-cr>
mwlang: anyway, you'll know for future reference :)
x0n has quit [Ping timeout: 240 seconds]
Xeago_ has joined #ruby
Xeago has quit [Read error: Connection reset by peer]
Xeago_ is now known as Xeago
x0n has joined #ruby
dfucci has joined #ruby
Iarfen has quit [Quit: No Ping reply in 180 seconds.]