I will introduce the misunderstanding about the module that I was studying Ruby.
⬇ Code when you misunderstood ⬇ ⬇ Correct code (I would appreciate it if you could point out any mistakes) ⬇ The difference is in "thinkable.rb" where the module is described.
require "./human"
The difference is whether or not there is.
In fact, there is no change in the execution result with or without it, but this description is unnecessary and should not be done.
### Why did you make such a mistake in the first place?
The reason why I made such a mistake is that I did not fully understand the module, but I used "self.hobby" defined in "human.rb" in the module. That's why you have to read "human.rb" as "tahinkable.rb". Because I thought that.
#### **`require "./human"`**
The result did not change with or without the description of, so when I asked the mentor at Teac Acadmy I was attending, he kindly answered.
The answer is
module works only after Mix-in Since "self.hobby" is also described to refer to the destination "self.hobby", it works when "./human" is not loaded but "Human" is loaded.
It was that. In other words, the module only works when it is loaded in a class.
I was able to eliminate one misunderstanding.
As mentioned above, I have introduced the misunderstanding that I had made as a beginner.
Recommended Posts