From: "Kurt M. Dresner" Date: 2003-07-15T06:11:53+09:00 Subject: Ruby CGI questions I'm trying to make a game (or at least something, so I can learn) with Ruby CGI. I'm having a really hard time with sessions. I have some variables that I want to save, but they are not strings. They are classes that I have defined. Is there any way to save them with a session without them just being converted to strings and then being read back in as strings when I load the session up? Here's what I have: #! /usr/bin/env ruby require "cgi" require "cgi/session" require "setdeck" require "set" require "setcollection" require "setboard" cgi = CGI.new("html4") sess = CGI::Session.new( cgi, "session_key" => "crappyset", "session_id" => "1234", #cgi.remote_addr, "prefix" => "setgame.", "tmpdir" => "/tmp") if sess["deck"].nil? deck = SetDeck.new sets = SetCollection.new board = SetBoard.new(12) deck.shuffle! else deck = sess["deck"] sets = sess["sets"] board = sess["board"] end board.place(deck.dealn(board.holes.size)) if cgi.has_key?('selections') tomark = cgi['selections'][0].split(',').collect { |x| x.to_i } tomark.each do |marked| board.select(marked) end end sess["deck"] = deck sess["sets"] = sets sess["board"] = board sess.update cgi.out{ cgi.html { cgi.head {"\n" + cgi.title {"What a crappy implementation of set!"}} + cgi.body {"\n" + cgi.pre{board.to_s} + cgi.br + cgi.form { cgi.textarea("selections") + cgi.br + cgi.submit("Check them!") } } } } I am just getting started with this, but I'm trying to learn how sessions work and having a hell of a time. I need to make sure that when deck, sets, and board are loaded up, they are loaded as a SetDeck, a SetCollection, and a SetBoard, respectively. Is there any way to do this without using Marshal? And if I need to use Marshal, how would I do that with sessions? -Kurt