jhass[m] changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.2, 3.0.4, 2.7.6: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
markong has quit [Ping timeout: 264 seconds]
s-liao-2000 has joined #ruby
s-liao-2000 has quit [Quit: Client closed]
shokohsc has quit [Ping timeout: 256 seconds]
<ule> Hey Ruby friends, do you know an one-line ruby magic to get this data-structure?
<leftylink> eh... I'd Enumerable#group_by, then Hash#transform_values, in which I'd use Enumerable#sum
shokohsc has joined #ruby
<leftylink> which could be one line if desired, I suppose
<leftylink> and I guess as the question was originally presented, after that it'll need another Enumerable#to_h on the end
<leftylink> hmm, no, an Enumerable#map on the end
<leftylink> but that's the irrelevant detail
<leftylink> the relevant detail is the first three functions used
<leftylink> using Enumerable#each_with_object is also a possibility, but for personal style reasons I wouldn't. but that's very workable
John_Ivan has quit [Ping timeout: 256 seconds]
sn0rl5x has joined #ruby
kiki_lamb has joined #ruby
kiki_lamb has left #ruby [#ruby]
<ule> Let me give a shot here
Rounin has quit [Ping timeout: 246 seconds]
<ule> Here is what I got ^
<ule> group_by + map + sum
<havenwood> Does a GenServer interface add value for Ractors? https://github.com/havenwood/gen_server/blob/main/example/basic_stack.rb
bougyman_ is now known as bougyman
<havenwood> ule: Ah, that's a fun challenge. I'll take a stab.
<ule> I wrapped everything in 3 lines but I know there is always a way to reduce things
<ule> :P
howdoi has quit [Quit: Connection closed for inactivity]
jpn has joined #ruby
jpn has quit [Ping timeout: 240 seconds]
<havenwood> ule: I get tempted to instead solve for `{"AAA"=>0.4, "BBB"=>0.8}`. :P
<havenwood> You have a succinct solution.
<havenwood> FWIW, I would `r.fetch(:list)`.
<havenwood> r.fetch(:list).group_by { _1.fetch(:id) }.transform_values { _1.sum { |hash| Float(hash.fetch(
<havenwood> :total)) }
<havenwood> But you want it restored, to an Array, and that gets messy going that ^ route.
<havenwood> r.fetch(:list).group_by { _1.fetch(:id) }.values.map { _1.reduce({}) { |acc, hash| acc.merge(hash) { |key, left, right| key == :total ? String(Float(left) + Float(right)) : left } } }
cocalero has joined #ruby
cocalero has quit [Client Quit]
Ziyan has joined #ruby
CalimeroTeknik has quit [Ping timeout: 246 seconds]
dannyAAM_ has joined #ruby
Milos_ has joined #ruby
polishdub has quit [Ping timeout: 246 seconds]
mahlon has quit [Ping timeout: 246 seconds]
dannyAAM has quit [Ping timeout: 246 seconds]
dannyAAM_ is now known as dannyAAM
Milos has quit [Ping timeout: 246 seconds]
cxl has quit [Ping timeout: 246 seconds]
cxl has joined #ruby
mahlon has joined #ruby
polishdub has joined #ruby
CalimeroTeknik has joined #ruby
dionysus69 has joined #ruby
kaivai has quit [Ping timeout: 256 seconds]
Sankalp- has joined #ruby
Sankalp has quit [Ping timeout: 246 seconds]
Sankalp- is now known as Sankalp
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
protektwar has joined #ruby
protektwar has joined #ruby
Ziyan has quit [Ping timeout: 264 seconds]
Ziyan has joined #ruby
davidw_ has quit [Ping timeout: 244 seconds]
RickHull has quit [Ping timeout: 276 seconds]
_ht has joined #ruby
ur5us has quit [Ping timeout: 255 seconds]
reset has quit [Quit: reset]
u0_a87 has joined #ruby
teclator has joined #ruby
mixfix41 has quit [Ping timeout: 268 seconds]
_ht has quit [Remote host closed the connection]
jpn has joined #ruby
jpn has quit [Ping timeout: 264 seconds]
u0_a871 has joined #ruby
u0_a87 has quit [Read error: Connection reset by peer]
lagash has quit [Ping timeout: 248 seconds]
dionysus69 has quit [Ping timeout: 264 seconds]
aeris has quit [Remote host closed the connection]
aeris has joined #ruby
u0_a871 has quit [Remote host closed the connection]
yossarian has quit [Ping timeout: 268 seconds]
jpn has joined #ruby
mixfix41 has joined #ruby
Ziyan has quit [Ping timeout: 248 seconds]
jpn has quit [Ping timeout: 240 seconds]
Furai has quit [Quit: WeeChat 3.5]
Rounin has joined #ruby
Ziyan has joined #ruby
Furai has joined #ruby
Ziyan has quit [Ping timeout: 268 seconds]
Ziyan has joined #ruby
TomyWork has joined #ruby
hresco3 has quit [Quit: WeeChat 2.3]
libsys has joined #ruby
libsys has quit [Remote host closed the connection]
jpn has joined #ruby
libsys has joined #ruby
Ziyan has quit [Ping timeout: 255 seconds]
Ziyan has joined #ruby
ur5us has joined #ruby
Thanzex8 has joined #ruby
Thanzex has quit [Ping timeout: 256 seconds]
Thanzex8 is now known as Thanzex
Ziyan has quit [Ping timeout: 244 seconds]
Ziyan has joined #ruby
Starfoxxes has quit [Ping timeout: 260 seconds]
ua_ has joined #ruby
Starfoxxes has joined #ruby
Ziyan has quit [Ping timeout: 256 seconds]
Ziyan has joined #ruby
dionysus69 has joined #ruby
Ziyan has quit [Ping timeout: 240 seconds]
Ziyan has joined #ruby
giorgian has joined #ruby
ssh0732 has joined #ruby
ur5us has quit [Ping timeout: 255 seconds]
Tempesta has joined #ruby
Ziyan has quit [Ping timeout: 240 seconds]
Ziyan has joined #ruby
Ziyan has quit [Ping timeout: 268 seconds]
Ziyan has joined #ruby
Jonopoly has joined #ruby
Ziyan has quit [Ping timeout: 248 seconds]
yxhuvud has quit [Remote host closed the connection]
yxhuvud has joined #ruby
Ziyan has joined #ruby
emcb543 has joined #ruby
emcb54 has quit [Ping timeout: 248 seconds]
emcb543 is now known as emcb54
Ziyan has quit [Quit: Textual IRC Client: www.textualapp.com]
Pixi has joined #ruby
Pixi` has quit [Ping timeout: 255 seconds]
markong has joined #ruby
s-liao-2000 has joined #ruby
sympt has quit [Read error: Connection reset by peer]
sympt has joined #ruby
protektwar has quit [Ping timeout: 240 seconds]
jpn has quit [Ping timeout: 268 seconds]
markong has quit [Ping timeout: 256 seconds]
jpn has joined #ruby
Ziyan has joined #ruby
markong has joined #ruby
jpn has quit [Ping timeout: 264 seconds]
sn0rl5x has quit [Quit: Client closed]
jpn has joined #ruby
jpn has quit [Ping timeout: 256 seconds]
John_Ivan has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 240 seconds]
s-liao-2000 has quit [Quit: Client closed]
<depesz> hi. my code was tested with rubocop, and one of the things it complained was https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/NumericPredicate
<depesz> I can't find information why is x.positive? better than x > 0
<depesz> anyone in here can shed some light on what is the reationale why comparing should be done with .positive?
<adam12> depesz: I'd say its _barely_ better, but if I was to argue it being better, it would be that the intent is more revealing, and you're sending a message to an object (Tell don't Ask or whatever).
<adam12> It's likely along the same lines of always using less than signs (don't use the greater than sign). https://www.agilealliance.org/resources/videos/dont-use-the-greater-than-sign-in-programming/
<adam12> Actually in this case, because it is _zero_, it's likely not about the greater than sign, but still worth considering.
<depesz> well, i have list of items, and i want to do stuff with the ones that have size > 0. basically: stuff.select { |b| b[:size] > 0 }.each do |b|
jpn has joined #ruby
<depesz> and I can't see, for the life of me, why select { |b| b[:size].positive? }.each do |b| would be better
jpn has quit [Ping timeout: 240 seconds]
siery has quit [Ping timeout: 244 seconds]
<havenwood> depesz: It's always slightly preferable to use a method without arguments that does the same thing as a method with arguments.
jpn has joined #ruby
<depesz> that I can understand because rubocop complains. my question is not - which is better, but why?
<depesz> what is the situation/explanation that "xxx" is better than "> 0"?
Ziyan_ has joined #ruby
Ziyan has quit [Ping timeout: 255 seconds]
jpn has quit [Ping timeout: 276 seconds]
s-liao-2000 has joined #ruby
dionysus69 has quit [Ping timeout: 240 seconds]
sn0rl5x has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 240 seconds]
wand has joined #ruby
<adam12> depesz: It's more intent revealing. You're not using a magic number, but more so saying "Tell me if you're positive or not".
Jonopoly has quit [Quit: WeeChat 3.0]
<depesz> well, truth be told I care only about whether the size is *not* zero, but it can never be < 0. so I did the > 0 test. i don't think i see it that way, but in process of thinking about it, i rewrite the loop in a way that rubocop doesn't complain, so i guess it should be fine.
<depesz> so, another question - in some docs I see that I should do 'gem "xxx"; require "xxx";' and in some just 'require "xxx";' - even when both of these are gems.
<depesz> what is the differentce, is 'gem "xxx"' ever needed, or is it a relic-code ?
<adam12> depesz: `gem "xxx"` in the Gemfile?
<adam12> In the Gemfile yes. In regular source, it's almost always "relic code".
<depesz> in source code. sorry
<adam12> It can be useful to force a specific version older version, but if you're using Bundler / Gemfile's then it's not necessary.
<depesz> ah, ok. thx.
davidw_ has joined #ruby
jpn has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
s-liao-2000 has quit [Quit: Client closed]
jpn has joined #ruby
jpn has quit [Ping timeout: 256 seconds]
Sankalp has quit [Quit: ZNC 1.7.2+deb3 - https://znc.in]
reset has joined #ruby
jpn has joined #ruby
lagash has joined #ruby
IsoLinCHiP has quit [Changing host]
IsoLinCHiP has joined #ruby
Sankalp has joined #ruby
aeris has quit [Remote host closed the connection]
aeris has joined #ruby
rvalue has quit [Ping timeout: 264 seconds]
rvalue has joined #ruby
dionysus69 has joined #ruby
TomyWork has quit [Remote host closed the connection]
sn0rl5x has quit [Ping timeout: 252 seconds]
Ziyan has joined #ruby
Ziyan_ has quit [Ping timeout: 255 seconds]
duds- has joined #ruby
dionysus69 has quit [Ping timeout: 264 seconds]
<adam12> Is anybody using rr for mocking?
markong has quit [Ping timeout: 248 seconds]
jpn has quit [Ping timeout: 256 seconds]
SunClonus has joined #ruby
_ht has joined #ruby
SunClonus has quit [Client Quit]
SunClonus has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 268 seconds]
SunClonus has quit [Read error: Connection reset by peer]
SunClonus has joined #ruby
SunClonus_ has joined #ruby
SunClonus_ has quit [Read error: Connection reset by peer]
SunClonus has quit [Ping timeout: 240 seconds]
SunClonus has joined #ruby
SunClonus_ has joined #ruby
SunClonus has quit [Ping timeout: 268 seconds]
Pixi has quit [Quit: Leaving]
SunClonus_ has quit []
SunClonus has joined #ruby
SunClonus has quit [Client Quit]
jpn has joined #ruby
jpn has quit [Ping timeout: 240 seconds]
joto has joined #ruby
<havenwood> depesz: It's also easier for a JIT to cache, etc, when there aren't arguments.
<havenwood> It's more likely the parser has an optimization to speed up prior to the JIT too.
<havenwood> It's also one less thing for the reader. I don't need to think about "positive?" but "> 0" it takes a split second to grok ">" or "<".
protektwar has quit [Ping timeout: 264 seconds]
joto has quit [Ping timeout: 276 seconds]
Pixi has joined #ruby
SunClonus has joined #ruby
szkl has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 264 seconds]
_ht has quit [Remote host closed the connection]
giorgian has quit [Read error: No route to host]
giorgian has joined #ruby
emcb54 has quit [Read error: Connection reset by peer]
emcb54 has joined #ruby
dionysus69 has joined #ruby
jpn has joined #ruby
dionysus69 has quit [Ping timeout: 256 seconds]
gr33n7007h has quit [Remote host closed the connection]
polishdub has quit [Quit: leaving]
gr33n7007h has joined #ruby
gr33n7007h has quit [Ping timeout: 240 seconds]
gr33n7007h has joined #ruby
Ziyan has quit [Quit: Textual IRC Client: www.textualapp.com]
ur5us has joined #ruby
giorgian has quit [Read error: Connection reset by peer]
giorgian has joined #ruby
jpn has quit [Ping timeout: 256 seconds]
jpn has joined #ruby
jpn has quit [Ping timeout: 268 seconds]
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
jpn has joined #ruby
some14u has joined #ruby
jpn has quit [Ping timeout: 276 seconds]
siery has joined #ruby
jpn has joined #ruby
markong has joined #ruby
jpn has quit [Ping timeout: 248 seconds]
gproto23 has joined #ruby
gproto23 has quit [Remote host closed the connection]
SunClonus has quit [Read error: Connection reset by peer]
some14u has quit [Quit: Textual IRC Client: www.textualapp.com]
SunClonus has joined #ruby
crundar has joined #ruby
jpn has joined #ruby
jpn has quit [Ping timeout: 264 seconds]
Inoperable has quit [Excess Flood]
Inoperable has joined #ruby
Inoperable has quit [Excess Flood]
entropie has quit [Ping timeout: 258 seconds]
mixfix41 has quit [Quit: out for now]
Inoperable has joined #ruby
entropie has joined #ruby
mixfix41 has joined #ruby
SunClonus_ has joined #ruby
SunClonus has quit [Ping timeout: 264 seconds]
giorgian has quit [Ping timeout: 240 seconds]
jpn has joined #ruby