[Ruby] Misunderstanding that I was using the module [Beginner]

I will introduce the misunderstanding about the module that I was studying Ruby.

⬇ Code when you misunderstood ⬇ ruby_module1.png ⬇ Correct code (I would appreciate it if you could point out any mistakes) ⬇ ruby_module2.png 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

[Ruby] Misunderstanding that I was using the module [Beginner]
About the matter that I was addicted to how to use hashmap
Was that so, the user_signed_in? method
[Rails] I was addicted to the nginx settings when using Action Cable.
A story I was addicted to when testing the API using MockMVC
[Ruby] I tried to summarize the methods that frequently appear in paiza
[Ruby] I tried to summarize the methods that frequently appear in paiza ②
[Ruby] Obtaining even values ​​using the even? Method
Methods that I found useful in Ruby
I was addicted to the roll method
I was addicted to the Spring-Batch test
I tried to summarize again the devise that was difficult at first sight
A story that I was really into when I did triple DES with ruby
[Ruby] Module
I tried using Docker for the first time
I was addicted to using RXTX on Sierra
I made blackjack with Ruby (I tried using minitest)
[API] I tried using the zip code search API
Why Java was the target language I hate
Command that the registered information was not found
I tried using the profiler of IntelliJ IDEA
I checked the number of taxis with Ruby
I want to get the value in Ruby
[Ruby] I want to make a program that displays today's day of the week!
When creating the top page, I was stuck with the handling of images (super beginner)
[Summary] What I noticed and did when I was told that the Oracle JDK was paid
The CSV file that I was able to download suddenly started to appear on the page.