Code:
class SomeIdioticSampleClass
def a_moronic_method
@any_instance_variable = any_value
@just_another_instance_variable * 2
end
def just_another_instance_variable
@just_another_instance_variable
end
def just_another_instance_variable=(new_value)
@just_another_instance_variable = new_value
end
end
In that excessively stupid example, I made it look idiotic on purpose, you can see two kinds of methods or "defs". The first method processes stuff like a computer would do it in the 50's or 60's while the second method is just a getter (method).
Getter or something that lets you get some instance variable, is like a store you don't own where you are allowed to purchase food or autoparts or tools but you can't sell them anything back.
A setter (method) like the third def above would be comparable to a store like DerVVulfman's pawn shop where you can sell them stuff if they find it worth buying it from you, a total stranger that rarely pay them a visit. (Well, you're Canadian, you're not supposed to walk around Maryland every single day of the year. ) The stranger would be any other class script, either you, MetalRenard, Kirito, LunarBerry, Nyakuya, etc. Anybody would be allowed to set any specific price to their product and try to sell it there. (Just skip the haggling part of the business here. )
An accessor in Ruby, a getter-setter combo, would be like Wulfo's shop but you would not only try to sell them stuff but also look for any interesting item like a guitar, a sword or a bow you might wanna buy for your personal collection.
SIDENOTES
As a sidenote I gotta admit that talking about super method is a BAD idea if a newbie is involved for super is one of Ruby's strangest exceptions to its rules. Let's say it's the only method that under certain circumstances might require to get a pair of () parentheses while no other method in Ruby actually needs them. (A lot of internal history of Ruby development is also involved here...)
a wolf once Wrote:Now that's what it is like if you have a super statement with parameters. It MUST be duplicating a method with an equal number of parameters.
Well, usually he would be right, BUT there is an exception in RGSS 1 and later versions (XP and later versions of the maker). If the last parameter of a child class's method is an array described as *array, then it might only look like it had the same number of arguments in both the child and parent class in the class scripts themselves (their defs). Sadly a call to those methods, using Class.method(argument1, argument2, argument3, argument4, etcera), might apparently have many more arguments or parameters or passed down values than those found in the defs where they were defined initially. WHY? Because the last *array parameter is like a large net waiting for some extra fish to catch than the amount the government would normally allow a single boat to catch in the sea. In the Class.method case etcera would be that special net's first victim.
In default scripts like Window_Base and so on you won't find such eccentricities or definitely crazy stuff at all, but I warn you it might happen a little bit more often in custom scripts.
By the way, super without () parentheses is not an innocent baby after all. It actually passes from 0 up to 17 arguments or passed down values to its parent class. Why zero as first possibility or option? Go ask Ruby's creator! The developers' team preferred to let you pass "nothing" as well in case the parent class did not need any parameter at all.
If you create your custom window class like I did here:
Code:
class MySharkyWindow < Window_Base
def initialize(x, y, width, height)
super
self.z = 1000
self.bitmap = Bitmap.new(width - 32, height - 32)
self.bitmap.draw_text(0, 0, width - 32, 24, "I'm a shark with a laser gun!")
end
end
You're passing down all four parameters to Window_Base, it's parent class. Yeah, Ruby let's you be quite lazy and skip the urge to specify what parameters the child class needs to pass down to its parent class. super is a perfect complement for lazy people!
"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