File: choose.rb

Project: Invitation to Ruby

#!/usr/bin/env ruby

def choose(one, two)
  if rand(2) == 0
    initial = one
    backup = two
  else
    initial = two
    backup = one
  end
  catch(:backup) {
    initial.call
    backup = nil
  }
  backup.call if ! backup.nil?
end


[ Index ][ Table of Contents ]
Generated by [ source2html ]