Skip to content

Instantly share code, notes, and snippets.

@stujo
Last active December 19, 2016 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stujo/c60567f10bb1eed5338071ec97b7d89d to your computer and use it in GitHub Desktop.
Save stujo/c60567f10bb1eed5338071ec97b7d89d to your computer and use it in GitHub Desktop.
How to include a module
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