<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>
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]