Topic: @
As you can see above, both classes have an instance variable @ named @name, what the at symbol @ does for name is to let the classes get an attribute or property called name, BUT they have different names!
That's true for now, but once you change one name, let's say CD's name, DVD's name won't be the same as CD's. Why? O_o? Well, that's because they have a similar but not identical attribute called name. (Identical means you won't find a single difference ever, no matter how many times you might check out both names.)
Do you remember wulfo said something about Xerox that you didn't understand? He later mention it was a photocopy machine, a device to make copies of any text, number, picture, etc. Well, Ruby and RGSS do have their own photocopy machine code to make it happen at any time you need to make a new copy of CD and DVD classes. Why? O_o? Because there's supposed to be tons of CD's and DVD's in the world! (Even if their actual contents suck like Scary movie or Twilight series.)
Instance would mean A Copy here. A single object called name attached to CD or DVD like an attachment to a post or an email.
Every time you call CD.new or DVD.new or Pet.new or Shop.new you're telling Ruby and RGSS that you want to get a Copy of CD or DVD or Pet or Shop with unique, "quite different", attributes or names or properties or contents. So every @variable will hold its own set of values, either a unique basket [] or {}, or some number like 1 or 1250 or a name "Puma meowing all night long Videoclip". Even if they all might start with the same value like "", there won't be a limit or restriction on what it could be later on. @name might start as "" but they change to "My First CD" if you change it inside CD class or from any other class or script with @cd.name = "My CD has got a new name!".
attr_accessor lets you change it from outside CD or DVD class with this @cd.name = "My CD has got a new name!"
But attr_reader would only let you get alias "retrieve" the name from CD's or DVD's @name like this @cd.name
No equal = sign, no "text", nothing on its right hand side.
The period or dot or point . is a connection or link between @cd and name to tell Ruby you want to get CD's name not any DVD's name.
Code:
class CD
attr_accessor :name
def initialize
@name = ""
end
end
Code:
class DVD
attr_accessor :name
def initialize
@name = ""
end
end
As you can see above, both classes have an instance variable @ named @name, what the at symbol @ does for name is to let the classes get an attribute or property called name, BUT they have different names!
Siletrea Wrote:How could it ever be different if both of them are called ""?
That's true for now, but once you change one name, let's say CD's name, DVD's name won't be the same as CD's. Why? O_o? Well, that's because they have a similar but not identical attribute called name. (Identical means you won't find a single difference ever, no matter how many times you might check out both names.)
Do you remember wulfo said something about Xerox that you didn't understand? He later mention it was a photocopy machine, a device to make copies of any text, number, picture, etc. Well, Ruby and RGSS do have their own photocopy machine code to make it happen at any time you need to make a new copy of CD and DVD classes. Why? O_o? Because there's supposed to be tons of CD's and DVD's in the world! (Even if their actual contents suck like Scary movie or Twilight series.)
Instance would mean A Copy here. A single object called name attached to CD or DVD like an attachment to a post or an email.
Every time you call CD.new or DVD.new or Pet.new or Shop.new you're telling Ruby and RGSS that you want to get a Copy of CD or DVD or Pet or Shop with unique, "quite different", attributes or names or properties or contents. So every @variable will hold its own set of values, either a unique basket [] or {}, or some number like 1 or 1250 or a name "Puma meowing all night long Videoclip". Even if they all might start with the same value like "", there won't be a limit or restriction on what it could be later on. @name might start as "" but they change to "My First CD" if you change it inside CD class or from any other class or script with @cd.name = "My CD has got a new name!".
attr_accessor lets you change it from outside CD or DVD class with this @cd.name = "My CD has got a new name!"
But attr_reader would only let you get alias "retrieve" the name from CD's or DVD's @name like this @cd.name
No equal = sign, no "text", nothing on its right hand side.
The period or dot or point . is a connection or link between @cd and name to tell Ruby you want to get CD's name not any DVD's name.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE