hoodwink.d enhanced

Sat May 31

Like the Rest of Us

Atmosphere

Kernel#maybe etc with Percentage::Chance

class Percentage def chance Chance.new(self) end class Chance attr_reader :odds, :happens alias :happens? :happens def initialize(percent) @odds = percent.amount @happens = @odds > Kernel.rand(100) end def of(&block) yield if happens? end end end module Kernel def maybe(percent = 50.percent, &block) if block_given? percent.chance.of &block else percent.chance.happens? end end def probably(&block) 80.percent.chance.of &block end def rarely(&block) 20.percent.chance.of &block end end
Kitty-wigs

Kitty Wigs