Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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 upRelated 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