Look what I found!! This is an archive of what my site/life was about 4-5 years ago. For the modern JobyBednar.com, try here.
JobyBednar.com
The future is here. It's just not widely distributed yet.
- William Gibson

Ruby Development
/root
  ./apple I
  ./articles
  ./code
  ./decode
  ./hobbies
  ./mac
  ./pics
  ./ruby
  ./www



 Use OpenOffice.org
dice.rb

1 #Advanced Gaming Dice 2 # 3 # dice = 3.d(6) --> array of 3 numbers of 1..6 (returns Dice) 4 # dice.roll --> new array of numbers (returns Dice) 5 # dice.total --> total value of numbers (returns Fixnum) 6 # dice.to_ascii --> if dice are 6 sided, outputs ascii of dice faces (returns String) 7 # dice.set(num, sides) --> new array of num numbers of 1..sides (returns Dice) 8 # dice.sides --> returns the set number of sides for the dice (read only) 9 # dice.count --> number of dice (read only) 10 class Dice < Array 11 attr_reader :sides, :count 12 13 def set(count, sides) 14 @count = count; @sides = sides 15 self.replace(Dice.new(count)).roll 16 end 17 18 def roll 19 self.map! {rand(@sides)+1} 20 self 21 end 22 23 def total 24 inject(0){|sum,v| sum+v} 25 end 26 27 def to_ascii 28 logic = [ 29 lambda{|n| '+-----+ '}, 30 lambda{|n| (n>3 ? '|O ' : '| ')+(n>1 ? ' O| ' : ' | ')}, 31 lambda{|n| (n==6 ? '|O ' : '| ')+ 32 (n%2==1 ? 'O' : ' ')+(n==6 ? ' O| ' : ' | ')}, 33 lambda{|n| (n>1 ? '|O ' : '| ')+(n>3 ? ' O| ' : ' | ')} 34 ] 35 str='' 36 5.times {|row| 37 self.each {|n| str += logic[row%4].call(n) } 38 str+="\n" 39 } if @sides == 6 and self.size > 0 and not self[0].nil? 40 str 41 end 42 end 43 44 class Fixnum 45 def d(sides) 46 Dice.new.set(self,sides).roll 47 end 48 end 49 50 #Example 51 require 'pp' #pretty print for the array 52 pp dice = 3.d(6) 53 puts dice.to_ascii 54 puts dice.total

 1	 #Example
 2	 require 'pp' #pretty print for the array
 3	 pp dice = 3.d(6)
 4	 puts dice.to_ascii
 5	 puts dice.total

 [3, 1, 4]
 +-----+ +-----+ +-----+
 |    O| |     | |O   O|
 |  O  | |  O  | |     |
 |O    | |     | |O   O|
 +-----+ +-----+ +-----+
 8