Modules
Learn what are modules and how to use them in Ruby.
We'll cover the following...
Definition
A module is a chunk of code we can include in a class or in another module:
Press + to interact
# MyModule contains logic for robot, human, and dogmodule MyModuleattr_accessor :x, :ydef initialize(options={})@x = options[:x] || 0@y = options[:y] || 0enddef rightself.x += 1enddef leftself.x -= 1enddef upself.y += 1enddef downself.y -= 1endendclass Robotinclude MyModuledef label'*'endendclass Doginclude MyModuledef upenddef leftenddef label'@'endendclass Humaninclude MyModuledef label'H'endend
In ...