<leftylink>
s/freeze the array/freeze the hash/ of course
<ox1eef>
nakilon: it is "dangerous" because it swallow exceptions you didn't expect. that pattern and those similar to it (eg rescue nil) are usually thought of as an anti-pattern.
<ox1eef>
i am talking about the "rescue nil" or "rescue 0" part, it can swallow exceptions you don't expect. you may call it as you like, i identify it as a pattern.
<nakilon>
isn't Integer("14 Foobars", exception: false) swallowing the exception?
<ox1eef>
only the exceptions you *expect*
<nakilon>
I don't see here any list of exception classes specified
<ox1eef>
usually, it raises a TypeError -if i'm not mistaken. "raise: false" keeps it to that. your example can swallow any other exception that may be raised.
<nakilon>
I see no proof
<ox1eef>
the proof is in how rescue 0 works. imagine, Integer(call_method) rescue 0; now, call_method may raise something you don't expect.
<nakilon>
but it isn't Integer(call_method)
<nakilon>
oh you mean v is a method?
<ox1eef>
yes, but it could be, and that is why that pattern is generally not recommended.
<nakilon>
speaking about exception supressing pattern is making me laugh
<nakilon>
since everyone have adopted stupid &.
<nakilon>
that is a cancer
<ox1eef>
i see it as a pattern as it is something programmers use to solve a problem, you can call it what you like
<ox1eef>
often use*
<nakilon>
I'm doing defensive programming for years and have never seen anyone caring about exceptions more
<ox1eef>
as i said at the start, it is fine by me - but there is that opinion, which i just explained, that discourages it
gr33n7007h has quit [Ping timeout: 240 seconds]
<nakilon>
ok I see the problem but it's only is if v becomes a method
<ox1eef>
right
gr33n7007h has joined #ruby
ur5us has joined #ruby
<nakilon>
did anyone catch the mouse click in terminal? as I understand it's possible with cruses but there is onle one sample in repo and no one even asked on SO, heh
<nakilon>
I'm thinking about making some interface for something parallel
pmwals09 has quit [Remote host closed the connection]
<nakilon>
you know what would fix the rescue problem?
<nakilon>
if ruby demanded to use () when calling a method without args
<nakilon>
I would be fine with that
<nakilon>
it would not be not convenient since we already need to write [] when calling lambda without args
SteveR has quit [Ping timeout: 256 seconds]
<ox1eef>
there's lambda {|foo, bar| p [foo, bar] }.(1, 2) as well. i think it's too late for ruby to change its syntax in such a dramatic way.
<nakilon>
isn't every major ruby update a drama? _--
<nakilon>
especially now
<nakilon>
I think there should be a balance that if we so many new features to the language, we should also polish the existing
<nakilon>
*if we add
<ox1eef>
the transition between major updates has always been mostly smooth for me, but i remember 1.9, 2.x and 3.1 introducing new syntax that's not backwards compatible, so there's that.
ur5us has quit [Ping timeout: 240 seconds]
gr33n7007h has quit [Ping timeout: 250 seconds]
gr33n7007h has joined #ruby
hanzo has quit [Quit: Connection closed for inactivity]
_ht has joined #ruby
shiru has quit [Quit: Lost terminal]
gr33n7007h has quit [Ping timeout: 250 seconds]
gr33n7007h has joined #ruby
lunarkitty has quit [Quit: Connection closed for inactivity]
lispy has quit [Quit: Leaving]
teclator has joined #ruby
leonthemisfit has joined #ruby
leonthemisfit has quit [Changing host]
leonthemisfit has joined #ruby
fef has joined #ruby
bluedust has joined #ruby
gr33n7007h has quit [Read error: Connection reset by peer]
ur5us has joined #ruby
gr33n7007h has joined #ruby
jmcgnh has quit [Ping timeout: 240 seconds]
<IsoLinCHiP>
Hmmm, you writing about ruby 3.1 made me notice the /de locale of ruby-lang.org hasnt mentioned 3.1 being released yet. Is it really worth having so many different locales and a prominent NEWS section if they arent equally curated?
TheBrayn has quit [Quit: WeeChat 3.3]
jmcgnh has joined #ruby
bluedust has quit [Remote host closed the connection]
bluedust has joined #ruby
bluedust has quit [Ping timeout: 240 seconds]
ur5us has quit [Quit: Leaving]
<nakilon>
feel free to contribute and translate
Guest9014 has joined #ruby
duds- has quit [Ping timeout: 276 seconds]
<ox1eef>
it is an effort of volunteers after all, it depends on who is interested in spending time to translate and has knowledge of german.
gproto23 has joined #ruby
re has joined #ruby
<depesz>
Hi. I have code that does gem 'whatever'; require 'whatever'; - how can I check which version of whatever is loaded? Specifically it's xdg gem.
<Sheilong>
I am parsing a game log file to extract some players. My approach using some regular expression works fine. I already did some debug and it correctly parses and extracts the players. However, when I attempt to save it in an array it is not properly append those players there. https://paste.ofcode.org/D6F69MubxWW6vrJtwvgdmg
<ox1eef>
Sheilong: first, i'd suggest each_with_object() over reduce().
<ox1eef>
after that, i'd suggest using print/puts to record misses and hits, so you have a better understanding of what's happening.
<Sheilong>
ox1eef: why each_with_object over reduce?
<nakilon>
why two times matches =
<Sheilong>
using an "|" with the two regex is getting wrong strings
<ox1eef>
Sheilong: i think it'd be easier to understand with each_with_object rather than reduce. you wouldn't need "next" anymore, just a guard around the push operation that populates the array.
<Sheilong>
I wouldn't know how to do that way.
Guest9014 has quit [Ping timeout: 256 seconds]
<ox1eef>
readlines(..).each_with_object([]) { |line, arr| if match(line); arr.push(line); end }
tsujp has joined #ruby
<ox1eef>
well, you'd push the captures rather than the whole line - hopefully you get the idea.
<Sheilong>
ox1eef: I see. The only problem is that I have two regexes. I once tried make a single one using an '|'. But I probably was doing something wrong because with | it parses strings that it shouldn't.
<nakilon>
havenwood how am I supposed to fix this error? https://dpaste.org/xUHL/slim as a user of the library Common
<nakilon>
(ignore line 13)
<nakilon>
looks like this works but I'm not sure if it's good: def self.request ; Async{ sleep( SEMAPHORE_TIME.async{ [@prev + 0.1 - Time.now, 0].max.tap{ @prev = Time.now } } ) }
<nakilon>
i.e. I added Async{...} in self.request
<Sheilong>
ox1eef: thanks. How I deal with the case when there is a position in the array returned by captures that is nil in such case?
<Sheilong>
I'd also need to return a list of unique values.
<ox1eef>
you can remove nil from an array by using .compact
<ox1eef>
arr.concat matches.captures.compact
<Sheilong>
ox1eef: How about returning the unique without having to do some sort of assignment?
<ox1eef>
i don't quite follow. .uniq can be used to remove duplicates from an array.
<leftylink>
dang. I need to reflect. I was about to say "this should not be done with each_with_object. it should be done with flat_map". but there's no reason for this "should". I'll take some time off to reflect. sorry for getting angry
<ox1eef>
yes, you're right - flat_map could work as well.
<Sheilong>
ox1eef: Yes. But from that block, how I'd do that?
tsujp has quit [Quit: Client closed]
tsujp has joined #ruby
analogsalad has joined #ruby
<Sheilong>
What I mean is about how to make that block yield the uniq from the resulting list without have to assign the output of that block to some variable and then call uniq.
<leftylink>
uniq may be called on any array, and each_with_object has returned an array.
<leftylink>
so, call it on that array, and no assignment is needed
<leftylink>
pandabot: rb [1, 2].flat_map do |x| [x, x] end.uniq
<leftylink>
now personally I wish that wouldn't type check and that with flat_map the block *has* to return a list, but I guess the decision was made too long ago