public
Rubygem
Description: Bringing random feelings to the Kernel since 2008
Homepage: http://github.com/linkingpaths/alea
Clone URL: git://github.com/linkingpaths/alea.git
Click here to lend your support to: alea and make a donation at www.pledgie.com !
alea /
name age message
file HISTORY Loading commit data...
file LICENSE
file Manifest.txt Sat Oct 04 09:45:24 -0700 2008 patch directory removed from manifest [aitor]
file POSTINSTALL
file README.markdown Sat Oct 04 09:39:17 -0700 2008 Fixed typo on chances_of_this_happens [aitor]
file Rakefile Sat Sep 20 16:55:08 -0700 2008 Initial commit [aitor]
file alea.gemspec Sat Oct 04 09:45:24 -0700 2008 patch directory removed from manifest [aitor]
directory config/
directory lib/
directory test/ Sat Oct 04 09:39:17 -0700 2008 Fixed typo on chances_of_this_happens [aitor]

alea

alea is a tiny gem that aim to bring some aleatory behavior to ruby Kernel.

Alea - Greek soldier (From Wikipedia, the free encyclopedia): "Alea was a Greek soldier who reputedly invented the dicing game 'Tabula'.This is the origin of the name aléatoire, meaning random.

Install

´sudo gem install linkingpaths-alea´

The junk

require 'alea'

# Add between 10 and 25 friends to a user
@user.add_friends rand_within(10..25)

# 75% chances of this happens
frequently do
  update_profile(@user) 
end

# 65% chances of this happens
probably do
  @group.activate!
end

# 20% chances of this happens
rarely do
  generate_404
end

# 5% chances of this happens
almost_never do
    grant_admin_privileges(@user)
end

# 95% chances of this happens
almost_always do
  post_incorrect_data_for_captcha
end

# 50% chances of true 
@group.moderated = maybe

# Calculate rounded percents 
send_mail_to 20.percent.of(the_community)


PS: I will probably give the option of set custom % via Alea::PROBABLY, Alea::RARELY etc. soon.

Credits

This code is based and inspired on some chunks of code appeared on the always entertaining, brilliant and funny project.ioni.st tumblelog.

More

http://github.com/linkingpaths/alea

http://github.com/linkingpaths/alea/wikis

Copyright (c) 2008 Linking Paths, released under the MIT license