Skip to content

Commit

Permalink
use sessions so names and stuff words don't repeat until used up
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Blake committed Feb 7, 2009
1 parent 8d4f4ed commit c414040
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions namepicker.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
require 'rubygems'
require 'sinatra'

module NameAndStuff
def self.name
names = File.read('./names.txt').strip.split(/\r|\n/)
names[rand(names.length)].upcase
get '/' do
if session[:names].nil? || session[:names].empty?
session[:names] = File.read('./names.txt').strip.split(/\r|\n/)
end

def self.stuff
stuff = ["WTF?!", "ALL THE FUCKING TIME!", "FTW!", "OMG!",
"ROTFLMAOASDF!!", "IN BED!", "now GTFO!",
"<small>secret python programmer iirc</small>"]
stuff[rand(stuff.length)]
if session[:stuff].nil? || session[:stuff].empty?
session[:stuff] = ["WTF?!", "ALL THE FUCKING TIME!", "FTW!", "OMG!",
"ROTFLMAOASDF!!", "IN BED!", "now GTFO!",
"<small>secret python programmer iirc</small>"]
end
end

name = session[:names][rand(session[:names].length)]
stuff = session[:stuff][rand(session[:stuff].length)]

session[:names].delete(name)
session[:stuff].delete(stuff)

get '/' do
@name_and_stuff = NameAndStuff.name + "... " + NameAndStuff.stuff
@name_and_stuff = name.upcase + "... " + stuff
haml :index
end

Expand Down

0 comments on commit c414040

Please sign in to comment.