[ next ] [ prev ] [ contents ] Invitation To Ruby

Logging

  1: #!/usr/bin/env ruby
  2: 
  3: def when_logging
  4:   yield if $do_logging
  5: end
  6: 
  7: $do_logging = false
  8: when_logging { puts "Never Printed" }
  9: 
 10: $do_logging = true
 11: when_logging { puts "Always Printed" }

Output

Always Printed



[ next ] [ prev ] [ contents ] Copyright 2002 by Jim Weirich.
All rights reserved.