02-03-2023, 04:33 AM
(This post was last modified: 02-03-2023, 05:00 AM by kyonides.
Edit Reason: Additional Comment
)
(02-03-2023, 03:52 AM)DerVVulfman Wrote:...Code:module MyModule
class MyClass
A = 'A'
B = 'B'
include MyModule
end
end
p MyModule::MyClass::MyClass::MyClass::MyClass::B
Honestly, the recursion is so bad, I could use this for the output:
Code:p MyModule::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::MyClass::B
What a mess made in hell!
OK, that case is even worse than the one previously presented on my previous post.
There is a caveat. It will not cause the recursion on its own, instead it will do it if it is commanded to keep looking for it.
Is that a serious issue?
It is more like a yes and not or a German jein.
What I mean is that it is a TERRIBLE IDEA for sure, but it is not like a method recursion where you cannot stop it from running unless you had added a valid condition there to break the invisible loop.
This will not cause you an immediate issue like running low on memory per se, but you will NOT be able to undo it unless you quit the program or application.
And even before Wulfo friendly? hijacks my thread again for the same reason, I will explain something that the average joe might not notice.
The first time you call that, it might not be an issue. Nonetheless, it will keep getting ugly the more times you keep calling it because it was used, let us say, inside a specific method. Memory CANNOT be freed soon just as expected. This translates to crafting messy code that is inexcusable at all.
Should we care about it?
The answer is yes!
Simply NEVER EVER ATTEMPT to run a real life program with such a weird and buggy inclusion of a module in a nested class.
Before I finish my short dissertation on this matter, I got to add something else.
Whatever has been included in that module is ALREADY AVAILABLE in the nested classes.
You do not need to include the container module at all!
Yet, there IS a caveat you should care about!
Code:
module Some
class Thing
end
end
The definition above will let you access everything you have defined in the Some module, but the one below does not ever let you get to its CONSTANTS.
Code:
class Some::Thing
# some code here!
end
Why it doesn't?
The answer is simple, it is because of its scope!
It cannot see where the CONSTANTS are located. You have reduced the scope to that Thing class only!
This means you will need to call all of its module's CONSTANTS like this:
Code:
Some::CONSTANT
And that is, my friends, a very unpractical way to achieve a simple goal.
Perhaps I could submit a request to the Ruby Core devs to make them forbid that inclusion in recent versions of Ruby at least.
"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