summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cgi/session/pstore.rb78
-rw-r--r--lib/matrix.rb53
2 files changed, 79 insertions, 52 deletions
diff --git a/lib/cgi/session/pstore.rb b/lib/cgi/session/pstore.rb
new file mode 100644
index 0000000000..d681d994a9
--- /dev/null
+++ b/lib/cgi/session/pstore.rb
@@ -0,0 +1,78 @@
+require 'cgi/session'
+require 'pstore'
+
+class CGI
+ class Session
+ def []=(key, val)
+ unless @write_lock
+ @write_lock = true
+ end
+ unless @data
+ @data = @dbman.restore
+ end
+ #@data[key] = String(val)
+ @data[key] = val
+ end
+
+ class PStore
+ def check_id(id)
+ /[^0-9a-zA-Z]/ =~ id.to_s ? false : true
+ end
+
+ def initialize session, option={}
+ dir = option['tmpdir'] || ENV['TMP'] || '/tmp'
+ prefix = option['prefix'] || ''
+ id = session.session_id
+ unless check_id(id)
+ raise ArgumentError, "session_id `%s' is invalid" % id
+ end
+ path = dir+"/"+prefix+id
+ path.untaint
+ unless File::exist? path
+ @hash = {}
+ end
+ @p = ::PStore.new path
+ end
+
+ def restore
+ unless @hash
+ @p.transaction do
+ begin
+ @hash = @p['hash']
+ rescue
+ @hash = {}
+ end
+ end
+ end
+ @hash
+ end
+
+ def update
+ @p.transaction do
+ @p['hash'] = @hash
+ end
+ end
+
+ def close
+ update
+ end
+
+ def delete
+ path = @p.path
+ File::unlink path
+ end
+
+ end
+ end
+end
+
+if $0 == __FILE__
+ STDIN.reopen("/dev/null")
+ cgi = CGI.new
+ session = CGI::Session.new cgi, 'database_manager' => CGI::Session::PStore
+ session['key'] = {'k' => 'v'}
+ puts session['key'].class
+ fail unless Hash === session['key']
+ puts session['key'].inspect
+ fail unless session['key'].inspect == '{"k"=>"v"}'
+end
diff --git a/lib/matrix.rb b/lib/matrix.rb
index fcb16d6c42..8e56fcbd97 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -126,13 +126,7 @@
# column_vectors
# array of column vectors
# to_a
-# converts each element to Array
-# to_f
-# converts each element to Float
-# to_i
-# converts each element to Integer
-# to_r
-# converts each element to Rational
+# converts to Array of Arrays
# PRINTING:
# to_s
# returns string representation
@@ -163,9 +157,6 @@
# CONVERTING:
# covector
# to_a
-# to_f
-# to_i
-# to_r
# coerce(other)
# PRINTING:
# to_s
@@ -936,27 +927,6 @@ class Matrix
@rows.collect{|row| row.collect{|e| e}}
end
- #
- # Applies #to_f to all elements to return a new matrix.
- #
- def to_f
- collect{|e| e.to_f}
- end
-
- #
- # Applies #to_i to all elements to return a new matrix.
- #
- def to_i
- collect{|e| e.to_i}
- end
-
- #
- # Applies #to_r to all elements to return a new matrix.
- #
- def to_r
- collect{|e| e.to_r}
- end
-
#--
# PRINTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
@@ -1315,27 +1285,6 @@ class Vector
end
#
- # Applies #to_f to each element to produce a new vector.
- #
- def to_f
- collect{|e| e.to_f}
- end
-
- #
- # Applies #to_i to each element to produce a new vector.
- #
- def to_i
- collect{|e| e.to_i}
- end
-
- #
- # Applies #to_f to each element to produce a new vector.
- #
- def to_r
- collect{|e| e.to_r}
- end
-
- #
# FIXME: describe Vector#coerce.
#
def coerce(other)