Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Writing a module is very similar to writing a class. Modules follow the same rules as classes and use CamelCase for naming. In this video, we're going to write the simplest possible module in Ruby.
Code Samples
Here is our simple module:
module SimpleModule
end
We can load it in to irb
by using the load
keyword and passing the file path:
irb> load "./simple_module.rb"
=> true
We can add a constant inside of the SimpleModule
by typing it's name in all upper case letters:
module SimpleModule
VERSION = 1.0
end
That can then be accessed using the constant resolution operator (::):
irb> SimpleModule::VERSION
=> 1.0
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Erdem Meral
25,022 Points0 Answers
-
Sean Flanagan
33,236 Points1 Answer
-
Rex L Baldon
3,090 PointsCan't type single nor double quotes in workspace console
Posted by Rex L BaldonRex L Baldon
3,090 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up