Skip to content

Instantly share code, notes, and snippets.

@cyrilchampier
Created November 29, 2019 15:16
Show Gist options
  • Save cyrilchampier/192e62264ea57272f2ccbd866ea9b88c to your computer and use it in GitHub Desktop.
Save cyrilchampier/192e62264ea57272f2ccbd866ea9b88c to your computer and use it in GitHub Desktop.
Module include: Real world example
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