Created
November 29, 2019 15:16
-
-
Save cyrilchampier/192e62264ea57272f2ccbd866ea9b88c to your computer and use it in GitHub Desktop.
Module include: Real world example
This file contains 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 Logging | |
def log(level, message) | |
File.open("log.txt", "a") { |f| f.write "#{level}: #{message}" } | |
end | |
end | |
class Service | |
include Logging | |
def do_something | |
begin | |
# do something | |
rescue StandardError => e | |
log(:error, e.message) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment