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
A namespace can be thought of as a container for other items. These things can be classes, constants, other modules, and more.
Code Samples
Multiple levels of modules can be used to namespace items:
module LaserBots
module Console
class Command
end
end
module World
class Player
attr_reader :name
def initialize(name)
@name = name
end
end
end
end
The classes, modules, and constants can then be accessed by using the constant resolution operator (::) to get to nested namespaces:
player = LaserBots::World::Player.new("Jason")
puts player.name
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
MICHAEL P
5,191 PointsNeed Help With Ruby Code Challenge: Inside of the LaserBots module, create a class called Player.
Posted by MICHAEL PMICHAEL P
5,191 Points1 Answer
-
Andrew Walters
8,876 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