A) "Sure hon', I'll give you my sandwich."
B) "Alright, let me make you another sandwich."
You get a sandwich from Mom, take some bites out of it, and gives it back to Mom.
Here's the key difference between "Pass-by-reference" and "Pass-by-value" that is important to understand: Is the object passed A) the original object, or B) a copy?
Pass-by-reference means you pass the original object. Any modifications you make to the object you receive is made on the original. Mom gets back her original sandwich that's half eaten.
Pass-by-value means you pass a copy of the object. Any modifications you make to the object you receive is made on the copy. Mom still has her original sandwich, but she also gets back the half eaten sandwich she made for you.
This difference is important to know, in any programming language - not just Ruby - because you could mistakenly pass an object by reference to a function that was not intended to be modified, or you could pass an object by value and wonder why wasn't the object updated by the function.
Hope that helps!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Imagine you're a five, and you want a sandwich.
Mom has a sandwich right now.
"Mom, can I have a sandwich? "
There's 2 things Mom can do:
A) "Sure hon', I'll give you my sandwich."
B) "Alright, let me make you another sandwich."
You get a sandwich from Mom, take some bites out of it, and gives it back to Mom.
Here's the key difference between "Pass-by-reference" and "Pass-by-value" that is important to understand:
Is the object passed A) the original object, or B) a copy?
Pass-by-reference means you pass the original object. Any modifications you make to the object you receive is made on the original. Mom gets back her original sandwich that's half eaten.
Pass-by-value means you pass a copy of the object. Any modifications you make to the object you receive is made on the copy. Mom still has her original sandwich, but she also gets back the half eaten sandwich she made for you.
This difference is important to know, in any programming language - not just Ruby - because you could mistakenly pass an object by reference to a function that was not intended to be modified, or you could pass an object by value and wonder why wasn't the object updated by the function.
Hope that helps!