<orbyt>
My Ruby skills are quite rusty - is there any scenario where `primary_search_term` would already have a value if this is the first reference to it in a module?
<orbyt>
My understanding of ||= is "if variable has no existing variable assign it this"
<adam12>
orbyt: primary_search_term is a local, so likely not.
<adam12>
bonhoeffer: exact error?
<adam12>
orbyt: and your understanding is _slightly_ wrong. It's basically if variable is nil or false.
<adam12>
orbyt: Show more code and we could probably look into it a bit more deeply, since a lot of context is lost by just showing the single statement.
<orbyt>
So if `primary_search_term` was null or a boolean == false, assign the following?
<orbyt>
Yea, I just saw that operator in a PR and it struck me as an error because I couldn't find how it could possible already have a value
<orbyt>
Wanted to check here before bringing it up in the PR
<adam12>
orbyt: Correct. It's often used for memoizing a value of a method call. `def foo; @foo ||= expensive_call_to_get_foo; end`.
<orbyt>
Cool, thanks
<orbyt>
We'll see what the PR submitter thinks
<adam12>
orbyt: If it's not passed into the method, and this is the first time it's being used, the ||= is probably unnecessary. But again, we lose a lot of context just seeing the small piece of the puzzle.
<orbyt>
Yea, I did a path search in rubymine and it's only used twice; there and then used again to reference a property: `term_display_name: primary_search_term.provider_description`
<adam12>
The `||=` is likely not hurting anything over just `=`, but it's definitely a source of indirection.
<adam12>
Maybe the entire method you pulled it from is wrong? The use of `#map` there looks wrong...
<adam12>
I'd expect `find` there.. since presumably the assignment would be a single value and not an array of nil's.
<adam12>
primary_search_term definitely doesn't need an or-equals
<orbyt>
Cool, figured as much.
<adam12>
I think the #map is working because it always returns a value.
<adam12>
if it was `#find` and never matched, line 63 would crash with NoMethodError.
<adam12>
So it's a happy accident that it works
<adam12>
(if it was `#map` and never matched it would be an error too)
<adam12>
This whole file would benefit of being a class with smaller methods, imho.
bonhoeffer has quit [Ping timeout: 268 seconds]
<orbyt>
Ok, made some comments and noted the issue with map
<orbyt>
Thanks for taking a look - I don't do server dev at this company but have a very small amount of ruby experience from years ago
drincruz has joined #ruby
Garb0 has quit [Quit: Garb0]
drincruz_ has quit [Ping timeout: 255 seconds]
lunarkitty has joined #ruby
altdev has joined #ruby
altdev has quit [Client Quit]
postmodern has joined #ruby
bonhoeffer has joined #ruby
bonhoeffer has quit [Remote host closed the connection]
bonhoeffer has joined #ruby
ur5us has quit [Ping timeout: 246 seconds]
_ht has quit [Remote host closed the connection]
Garb0 has joined #ruby
Garb0 has quit [Read error: Connection reset by peer]
Garb0 has joined #ruby
ikke has joined #ruby
Garb00 has joined #ruby
Garb0 has quit [Ping timeout: 255 seconds]
<ikke>
ruby-magic is failing with the error Magic::MagicError (could not find any valid magic files!). If I strace a simple script, I see this: https://tpaste.us/Lm6W. Why is it trying to look for those files in that location? /usr/local/bundle/gems/ruby-magic-0.4.0/ports does not exist.
<ikke>
This is in a ruby:2.7-alpine docker image
<ikke>
libmagic is installed, which has the mgc file in usr/share/misc/magic.mgc
bandithijo has joined #ruby
isekaijin has joined #ruby
bonhoeffer has quit [Remote host closed the connection]
bonhoeffer has joined #ruby
bandithijo has quit [Quit: WeeChat 3.2-rc1]
bonhoeffer has quit [Remote host closed the connection]