11-14-2018, 04:05 AM
The @ symbol is confusing? Well, it basically means that the variable belongs to THAT particular class.
If I made a class called Shelley and a class called Miriam, each might have a variable called @hair_color. I could set the @hair_color variable in the Shelley class to 'sandy_blonde', and set the @hair_color variable in the Miriam class to 'auburn_brown '. Each has its own variable, even though they have the same name. If I tried using the $hair_color value in either class, one would overwrite the other.
STUDY TIME: Look at any of the initialize methods in the default classes. They tend to have @instance variables belonging just to them.... mostly.
Oh, wow. Um... Yeah. Xerox is the manufacturer of a a popular office copy machine. In fact, it was the essential STANDARD for copiers. So back in the day, we just called copiers 'Xerox', just like how we call adhesive bandages 'Bandaids'
Hey, I use phrases like 'oft' for often and other old phrases from before I was borne. BUT I don't think I have ever used 'nary'.
So when I said "that your child is a literal XEROX of the parent", I meant it was a near-perfect copy or duplicate. And well, yeah. The super() statement is a way of letting you add new content to an existing method. It's just that the super() statement "IS" the old content and you're writing the new content around it.
We could just say, we're taking the original 'goofy_method' method and adding two more statements to the start, and two more statements when the original method would have been done.
TEST TIME: So, show me an example of a method using the super() statement. Just an interpretation of what you think it means. This is a no pressure thingie. Just a gauge for discussion to see how I'm doing as a teacher and stuff. More like a test on ME.
If I made a class called Shelley and a class called Miriam, each might have a variable called @hair_color. I could set the @hair_color variable in the Shelley class to 'sandy_blonde', and set the @hair_color variable in the Miriam class to 'auburn_brown '. Each has its own variable, even though they have the same name. If I tried using the $hair_color value in either class, one would overwrite the other.
STUDY TIME: Look at any of the initialize methods in the default classes. They tend to have @instance variables belonging just to them.... mostly.
Oh, wow. Um... Yeah. Xerox is the manufacturer of a a popular office copy machine. In fact, it was the essential STANDARD for copiers. So back in the day, we just called copiers 'Xerox', just like how we call adhesive bandages 'Bandaids'
Hey, I use phrases like 'oft' for often and other old phrases from before I was borne. BUT I don't think I have ever used 'nary'.
So when I said "that your child is a literal XEROX of the parent", I meant it was a near-perfect copy or duplicate. And well, yeah. The super() statement is a way of letting you add new content to an existing method. It's just that the super() statement "IS" the old content and you're writing the new content around it.
Code:
def goofy_method
blah_blah_blah_new_statement1
blah_blah_blah_new_statement2
super()
blah_blah_blah_new_statement3
blah_blah_blah_new_statement4
end
We could just say, we're taking the original 'goofy_method' method and adding two more statements to the start, and two more statements when the original method would have been done.
TEST TIME: So, show me an example of a method using the super() statement. Just an interpretation of what you think it means. This is a no pressure thingie. Just a gauge for discussion to see how I'm doing as a teacher and stuff. More like a test on ME.