Caffeine "Sanity" Check!

I should keep my sanity level on check..No excess cup of coffee anymore! Or else..

@cups_of_coffee = 0

def drink_coffee(&block)
  @cups_of_coffee += 1

  yield(@cups_of_coffee) if block_given?
end

def caffeine_sanity_check(cups_of_coffee)
  case cups_of_coffee
    when 0
      warn "Low"
    when 1
      puts "Sane.."
    else
      raise CaffeineExcessException, "You'll probably go crazy in 1..2..3.."
  end
end

class CaffeineExcessException < Exception
  def initialize(message)
    @message = message
  end

  def to_s
    "Fatal: Possible insanity ahead! #@message"
  end
end

 

drink_coffee { |cof| caffeine_sanity_check(cof) }        # first call

=> Sane..

drink_coffee { |cof| caffeine_sanity_check(cof) }        # second and successive calls

=> CaffeineExcessException: Fatal: Possible insanity ahead! You'll probably go crazy in 1..2..3..

P.S. I'm insane today..

Drawing Out Inspiration

2011-06-20-201745
I’m in a current state of self where I try to find or reminisce things that would inspire me to be creative, resourceful, active and jolly. =)

About

programmer from cebu, philippines

TwitterFacebook