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& #39;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& #39;s value.
If there isn& #39;t a per-site variable defined, then if you call that varible it& #39;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& #39;s value. And that& #39;s how I get a "default" value for a variable.
(falsy meaning that it& #39;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& #39;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& #39;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& #39;t fuckken binary and I& #39;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& #39;s try another method.
Just fire up the IRB console, drop in some dummy variables, and play around, you know? It& #39;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& #39;s see what& #39;s up

The IRB responds "true".

Just to make sure that "true" wasn& #39;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& #39;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& #39;t defined, so it sets e to the value of b, "test"
Okay, but let& #39;s back up here. The code that I don& #39;t quite understand isn& #39;t setting a new variable to one variable SINGLE PIPE another variable ( ie, d = a | b). It& #39;s setting a variable to itself SINGLE PIPE another variable (ie, c = c | b).

So let& #39;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& #39;s make some arrays"
So then I made a few new variables

x = nil (which, looking back, I should& #39;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& #39;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: