Last active
December 19, 2016 18:24
-
-
Save stujo/c60567f10bb1eed5338071ec97b7d89d to your computer and use it in GitHub Desktop.
How to include a module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Timeable | |
def start_timer | |
@timeable_timer = Time.now.utc | |
end | |
def end_timer | |
Time.now.utc - @timeable_timer | |
end | |
end | |
class DragRace | |
include Timeable | |
end | |
race = DragRace.new | |
race.start_timer | |
sleep(3) | |
p race.end_timer | |
puts "See http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/ for more info" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment