操作
Wiki¶
CGI用サーバー¶
#!/usr/bin/env ruby require 'webrick' document_root = './' rubybin = '~/.rbenv/shims/ruby' server = WEBrick::HTTPServer.new({ DocumentRoot: document_root, BindAddress: '0.0.0.0', CGIInterpreter: rubybin, Port: 8080 }) ['INT', 'TERM'].each {|signal| Signal.trap(signal){ server.shutdown } } server.start
階上を計算するCGI¶
#!/usr/bin/env ruby require 'cgi' def fact(n) n == 0 ? 1 : n * fact(n - 1) end cgi = CGI.new n = cgi['n'].to_i print cgi.header puts "" puts "" puts "#{n} ! = #{fact(n)}" puts ""
Yuumi Yoshida さんが9年以上前に更新 · 3件の履歴