havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.0, 3.0.3, 2.7.5: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
bluedust_ has quit [Read error: Connection reset by peer]
weaksauce has joined #ruby
ur5us has quit [Ping timeout: 240 seconds]
pmwals09 has joined #ruby
Guest9014 has quit [Ping timeout: 256 seconds]
pmwals09 has quit [Remote host closed the connection]
pmwals09 has joined #ruby
hanzo has joined #ruby
lispy has joined #ruby
ur5us has joined #ruby
gr33n7007h has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
whysthatso125 has quit [Quit: Ping timeout (120 seconds)]
whysthatso125 has joined #ruby
Rounin has joined #ruby
SteveR has joined #ruby
gr33n7007h has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
shiru has joined #ruby
gr33n7007h has quit [Ping timeout: 250 seconds]
ralu has quit [Ping timeout: 240 seconds]
ur5us has quit [Quit: Leaving]
ralu has joined #ruby
ur5us has joined #ruby
ur5us has quit [Remote host closed the connection]
lunarkitty has joined #ruby
gr33n7007h has joined #ruby
gr33n7007h has quit [Read error: Connection reset by peer]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
<nakilon> ox1eef not sure why it should be dangerous
<nakilon> we actually have a profit of not remembering what is nil.to_i
<nakilon> and not calling unnecessary Integer#to_i
<nakilon> leftylink I just don't use block form at all; just do h[k] ||= []; h[k]...
<leftylink> sometimes that's all right. otherwise when you're about to freeze the array you have to remember to unset the default proc
<leftylink> pandabot: rb h = Hash.new { |h, k| h[k] = [] }; h[:a] << 5; h.freeze; h[:b]
<pandabot> stderr: -e:2:in `block in <main>': can't modify frozen Hash: {:a=>[5]} (FrozenError) - exit 1 - https://carc.in/#/r/cnyy
<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.
<nakilon> that isn't a pattern
<leftylink> pandabot: rb h = Hash.new { |h, k| h[k] = [] }; h[:a] << 5; h.default_proc = nil; h.default = [].freeze; h.freeze; h[:b]
<nakilon> that is just a single Integer() method
<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.
<nakilon> via Gem
bluedust has joined #ruby
bluedust has quit [Remote host closed the connection]
<depesz> ah, so i use: Gem.loaded_specs["xdg"].version - thanks a lot.
<depesz> this leads to problematic question, though - how do I figure out when api was changed. didn't thought that one through :/
Sheilong has joined #ruby
<nakilon> depesz either inspect github commits checking the tags
<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.
<ox1eef> something like that may work
<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
<pandabot> [1, 2] - https://carc.in/#/r/co1g
<leftylink> no assignments there
<Sheilong> Thanks guys.
<Sheilong> I combine the regular expression into a single one and did the following https://paste.ofcode.org/395z5mQvYMCMRmUZBnYZx9p
<Sheilong> Is it okay?
<Sheilong> I added next and unless to avoid writing two lines with if
bluedust has joined #ruby
<leftylink> pandabot: ri Enumerable#flat_map
<leftylink> to me it's not okay unless it uses flat_map unless each_with_object, but not everyone shares the same standards of okay, I understand.
<leftylink> s/flat_map unless/flat_map instead of/
bluedust has quit [Ping timeout: 240 seconds]
Guest59 has joined #ruby
<Sheilong> I am trying something like File.readlines(path).flatmap do |line| |line.match(re_pattern_players.captures.compact)| end.uniq
Noktar has joined #ruby
<Sheilong> with flat_map it is adding a nil to the resulting list.
<ox1eef> see above
<leftylink> code does what yout ell it to do, no more no less
Guest59 has quit [Quit: Client closed]
<leftylink> pandabot: rb [1].flat_map { next }
<pandabot> [nil] - https://carc.in/#/r/co1h
<Sheilong> Sorry for being such a noob : (
<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
analogsalad has quit [Quit: bye]
constxd has joined #ruby
Noktar has left #ruby [#ruby]
<nakilon> pandabot: rb [1].flat_map { next [] }
<gr33n7007h> >> 1 + 1
<ruby[bot]> gr33n7007h: # => 2 (https://carc.in/#/r/co2f)
<gr33n7007h> who fixed it
<gr33n7007h> >> RUBY_VERSION
<ruby[bot]> gr33n7007h: # => "3.0.1" (https://carc.in/#/r/co2g)
<adam12> gr33n7007h: jhass[m] figured it out. LetsEncrypt cert issue IIRC.
<gr33n7007h> adam12: ah, nice!
alex[m] has quit [Quit: Client limit exceeded: 20000]
gr33n7007h has quit [Read error: Connection reset by peer]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
SteveR has joined #ruby
gr33n7007h has quit [Quit: WeeChat 3.4]
fef has quit [Ping timeout: 276 seconds]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
goldfish has joined #ruby
oxfuxxx has joined #ruby
gr33n7007h has joined #ruby
bluedust has joined #ruby
gproto23 has quit [Ping timeout: 268 seconds]
tsujp has quit [Quit: Client closed]
Guest9014 has joined #ruby
oxfuxxx has quit [Ping timeout: 240 seconds]
Guest9014 has quit [Ping timeout: 240 seconds]
___nick___ has joined #ruby
bluedust has quit [Remote host closed the connection]
<Hess> >> 10.times.to_a
alex[m] has joined #ruby
<ruby[bot]> Hess: # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] (https://carc.in/#/r/co32)
<Hess> nice
<Hess> >> (999**999).times.to_a
<ruby[bot]> Hess: # => (https://carc.in/#/r/co33)
<Hess> shrug
havenwood has quit [Quit: The Lounge - https://thelounge.chat]
havenwood has joined #ruby
goldfish has quit [Ping timeout: 268 seconds]
gr33n7007h has quit [Ping timeout: 240 seconds]
lispy has joined #ruby
gr33n7007h has joined #ruby
gproto23 has joined #ruby
ralu has quit [Ping timeout: 240 seconds]
ralu has joined #ruby
SteveR has quit [Ping timeout: 256 seconds]
ur5us has joined #ruby
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #ruby
oxfuxxx has joined #ruby
<legit> >> puts "test"
<ruby[bot]> legit: # => test ...check link for more (https://carc.in/#/r/co4r)
<legit> Oh, I see.
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
<Hess> >> Dir.pwd
<ruby[bot]> Hess: # => (https://carc.in/#/r/co4v)
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
___nick___ has joined #ruby
gr33n7007h has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
oxfuxxx has quit [Quit: can you please adjust your IRC quit message to be less transphobic?]
gproto23 has quit [Remote host closed the connection]
gproto23 has joined #ruby
___nick___ has quit [Ping timeout: 256 seconds]
_ht has quit [Remote host closed the connection]
lispy has quit [Quit: Leaving]
<havenwood> Hess: Please leave the bot to sharing examples. :)
roshanavand has joined #ruby
havenwood has quit [Quit: The Lounge - https://thelounge.chat]
havenwood has joined #ruby
havenwood has quit [Client Quit]
havenwood has joined #ruby
Artyom has joined #ruby
gr33n7007h has quit [Ping timeout: 250 seconds]
Artyom has quit [Client Quit]
gr33n7007h has joined #ruby
Rounin has quit [Ping timeout: 268 seconds]
Guest9014 has joined #ruby
gr33n7007h has quit [Ping timeout: 240 seconds]
gr33n7007h has joined #ruby
gproto23 has quit [Ping timeout: 256 seconds]
roshanavand has quit [Quit: Leaving]
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
weaksauce has quit [Quit: Textual IRC Client: www.textualapp.com]
jimeh has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 240 seconds]
weaksauce has joined #ruby
jimeh has joined #ruby
gr33n7007h has quit [Ping timeout: 250 seconds]
weyhmueller has quit [Quit: ZNC 1.8.2 - https://znc.in]
Guest9014 has quit [Ping timeout: 268 seconds]
weyhmueller has joined #ruby