Created
January 8, 2015 12:47
-
-
Save jensendarren/3309b478ec68b1ae7fe5 to your computer and use it in GitHub Desktop.
An example of using STDOUT Logger in Ruby
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
# http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html | |
require 'logger' | |
class CoffeeShop | |
attr_reader :logger | |
def initialize(name) | |
@name = name | |
@menu = [] | |
@logger = Logger.new(STDOUT) | |
end | |
def introduce_coffee(coffee) | |
logger.debug "introducing a new coffee #{coffee}" | |
@menu.push(coffee) | |
log_menu_item_count | |
end | |
def withdraw_coffee(coffee) | |
logger.debug "withdrawing a new coffee #{coffee}" | |
@menu.delete(coffee) | |
log_menu_item_count | |
end | |
private | |
def log_menu_item_count | |
logger.debug "menu item count: #{@menu.count}" | |
end | |
end | |
shop = CoffeeShop.new("Costa") | |
shop.introduce_coffee("Angkorian") | |
shop.introduce_coffee("Vietnamese") | |
shop.withdraw_coffee("Angkorian") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment