View Single Post
Old 02-24-2025, 06:23 PM  
Huggles
GFY'S #1 retard
 
Industry Role:
Join Date: Feb 2003
Location: Kelowna
Posts: 10,718
Quote:
Originally Posted by CaptainHowdy View Post
You still have to know code to prompt code ??
Yeah but you can ask the AI to explain the code to you... Best part is, you can ask it to explain it to you like you're a drunk retard, and it will go slow and even provide you examples in booze-speak.

Describe, in terms an alcoholic would understand, how Ruby stores a variable and retrieves it when it is called for a function. How does the code work?

ChatGPT said:
Alright, let’s break it down in terms of drinking.

Storing a Variable in Ruby = Pouring a Drink
Think of a variable in Ruby like a glass at the bar. When you assign a value to it, it's like pouring a drink into that glass.

Example:

ruby
Copy
Edit
whiskey = "Jameson"
Here, you have a glass called whiskey, and you just poured "Jameson" into it.

Retrieving the Variable = Taking a Sip
When you call the variable later, Ruby acts like a bartender remembering your order. It grabs the same glass and gives you what’s inside.

Example:

ruby
Copy
Edit
puts whiskey
This is like saying, "Hey bartender, what’s in my whiskey glass?" And the bartender (Ruby) replies:

Jameson

How Functions Use Variables = Mixing a Cocktail
Now, let's say you want to mix a drink (use a function). You don’t want just straight Jameson—you want an Old Fashioned.

Example function:

ruby
Copy
Edit
def make_old_fashioned(base_whiskey)
"#{base_whiskey} + bitters + sugar + orange peel"
end
This function takes in a variable (a bottle of whiskey), adds ingredients, and returns a cocktail.

Now, let’s call the function using our whiskey variable:

ruby
Copy
Edit
puts make_old_fashioned(whiskey)
Ruby sees the whiskey variable, grabs "Jameson" from it, and the function makes:

Jameson + bitters + sugar + orange peel

This is like asking the bartender, “Make me an Old Fashioned with my Jameson.”

How Ruby Actually Works Behind the Scenes
Assigning a variable:
Ruby creates a label (like a drink order) that points to a value in memory (the bottle on the shelf).
Calling a variable:
Ruby looks up that label and grabs the value from memory (pours your drink).
Passing a variable to a function:
Ruby hands the bartender the bottle and says, "Use this in the recipe."
Returning a result:
The function mixes the drink and hands it back.
Key Takeaways (For an Alcoholic Mindset)
Variables are like glasses at a bar—they hold something until you drink (use) them.
Functions are like bartenders—they take your ingredients, mix them, and give you back something new.
Ruby memory is the liquor shelf—it stores bottles (values) and retrieves them when needed.
So next time you're coding in Ruby, just think of yourself as a drunk bartender managing drinks efficiently.
🍻
__________________
I make my money from people jerking off
Huggles is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote