Why is Class Animal is defined in the module Zoo which is stored - ProProfs Discuss
Advertisement

Why is Class Animal is defined in the module Zoo which is stored in the file zoo_file?

Asked by Ary.Alva, Last updated: Mar 26, 2024

+ Answer
Request
Question menu
Vote up Vote down

1 Answer

John Smith

John Smith

John Smith
John Smith

Answered Feb 09, 2017

To use the code from module Zoo you have to include the statement require zoo_file
To avoid prefixing Animal methods with "Zoo::", the statement "include Zoo" should be located anywhere in the code after the statement "require zoo_file" and before methods from Animal class are used
Ruby code can be grouped into modules

The statements A, D and E are correct. Ruby code can be grouped in the module. To use classes defined in the module, the statement require module_file_name has to be present. To allow using the class methods without ModuleName::, the statement include ModuleName has to be included in the code after the statement require module_file and before any methods are used.
upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.