Exercise 10


#1



https://www.codecademy.com/courses/ruby-beginner-en-zfe3o/1/4?curriculum_id=5059f8619189a5000201fbcb


I'm not exactly stuck but have a question. When requiring the given module, we use 'date' but the module name is 'Date' yet works nonetheless. When I tried capitalizing the 'D' in the require statement, it does not work. Is this method a case-sensitive method where all characters must be lower case?


Replace this line with your code.


#2

Good question!

In most cases, when we do require 'module' in Ruby what we're telling Ruby to is to to allow us to use what's contained in the file with that name.

So, in the case of require 'date', we're asking Ruby to find a file called date (most likely with a file extension of .rb), and then give us access to what's in that file. By convention classes in Ruby, like Date will be contained in a file with the same name, except it will be lowercase. So, basically, the Date class comes from the date file.

Hopefully that makes sense!


#3

:bow: thats good

can such a file include more than one module??


#4

Yeah. It doesn't happen too often in the core Ruby language itself, but It's quite a common way of organizing code in Ruby projects (especially larger codebases). You'll see a lot of examples of this as you begin to look at other people's code in the future.


#5

cool
so till now i can say that i can use the scope resolution operation to choose from two constants -with the same name- in diferent modules in the same file ??


#6

That's correct! That's a good example of how namespacing and the scope resolution operator works in Ruby


#7

This was a very helpful response! Thank you! :>


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.