okay so today I was trying to figure out why a change I made to a chef cookbook was causing nginx to be recompiled every time ... and I came across a variable that was set to itself, SINGLE PIPE, and then a string literal inside quotes & square brackets.
Now in ruby, like most programming languages which I have encountered over the years, DOUBLE PIPE is the "or" comparison operator. And I actually use this all the time in the chef recipes I regularly maintain for our internal stuff.
Here's an example I updated earlier this week. These are the variables that fill in the blanks on nginx site template files, and the DOUBLE PIPE ( || ) here means that if there is a per-site variable defined in a databag, use that. Otherwise the default variable on the other side
This works because if the per-site variable is defined, it satisfies the "truthiness" (or whatever???) of the or comparison, and the template variable is assigned the per-site variable's value.
If there isn't a per-site variable defined, then if you call that varible it's nil, so that side of the comparison of X || Y is falsy. Thus the left side is false, the template variable gets assigned the right side's value. And that's how I get a "default" value for a variable.
(falsy meaning that it's a thing that evals to false, as opposed to truthy; it has negative "truthiness" or whatever)
But what the actual aitch-ee-double-hockey-sticks (single hockey stick) is SINGLE PIPE?
So, I mean, you do what you gotta do, type "ruby operators" into google because typing "ruby |" sure as shit doesn't give any good results. Google is still real bad with that kind of thing.
Anyway, no matter where you look, high or low, O'Reilly or wikibooks or some random tutorial sites, the SINGLE PIPE operator is ruby is "bitwise or"

BITWISE OR

What the the SHIT
Well configure flags sure aren't fuckken binary and I'm not seeing how comparating any bits of a string is gonna make nginx recompile or not recompile every chef-client run. And as mentioned before, the | character is REALLY HARD TO GOOGLE so, eh, let's try another method.
Just fire up the IRB console, drop in some dummy variables, and play around, you know? It's like the 2020 version of booting up an Apple //e and typing

10 PRINT TOOT TOOT
20 GOTO 10

and learning how BASIC works
So I make a few variables. "a" I define as nil, i.e. the null set, that is, UNDEFINED, you know, whatever you want to call the absence of something, a lack of substance, the vast, unquantifiable void that surrounds us, the empty infinity of space.

Also I make "b" & "c" strings
Then, as a test, I make a new variable, d, and I define it as

b | c

There, SINGLE PIPE operator, let's see what's up

The IRB responds "true".

Just to make sure that "true" wasn't just it letting me know I defined d, I asked it for the value of d.

true

TRUE?!?!?!
Okay just to make sure I haven't fallen into the wormhole, to the Beyond part in the back of every Bed Bath & Beyond, I try the DOUBLE PIPE assignment, like I use regularly in my own recipes.

It works the way it should. a isn't defined, so it sets e to the value of b, "test"
Okay, but let's back up here. The code that I don't quite understand isn't setting a new variable to one variable SINGLE PIPE another variable ( ie, d = a | b). It's setting a variable to itself SINGLE PIPE another variable (ie, c = c | b).

So let's try that.

OH GREAT AN ERROR
"Well, you know what," I thought to myself today shortly before lunch as I stared at this straight up hogwash that ruby was farting in my general direction, "that statement has square brackets, which is an array, or hash, gosh I always get those mixed up. Let's make some arrays"
So then I made a few new variables

x = nil (which, looking back, I should've made [], that is, an empty array, which is also the empty set if you think about it, you know, a 0 with a strike through it we wrote at the end of proofs in maybe…algebra II?)
y = ["butt"]
z = ["toot"]
Bathos aside, after assignments I went straight for the jugular:

y = y | z

You know what that evals to?

What do you think? True? False? An error? SOME BINARY BULLSHIT?!
Nah dude, it evaluates to a new array with the contents of the two arrays concatenated together

WHAT THE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Just for funsies, I tried creating a new variable, and setting that variable to one (nil) var SINGLE PIPE another (array) var, that is,

w = x | z

Which comes back "true" because, WHY THE HELL NOT I GUESS. WHATEVER, THE WHOLE OF THE RUBY OPERATOR LAW SHALL BE DO WHAT THOU WILT
Although I just thought to assign a variable to this bizarre construction where both sides are arrays, and yep, it concatenates them
So anyway, if you want to get good at a progamming language or debug code or learn the meaning of life, the universe, & everything, jupiter & beyond the infinite, so long & thanks for all the fish, young zaphod plays it safe, like, uh, just don't okay. All that is very well but…
we must cultivate our garden.

goodnight
You can follow @bennyfactor.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: