22件ヒット
[1-22件を表示]
(0.066秒)
検索結果
-
cgi (37.0)
-
CGI プログラムの支援ライブラリです。
...==== フォームフィールドの値を得る
//emlist[][ruby]{
require "cgi"
cgi = CGI.new
values = cgi['field_name'] # <== 'field_name' の配列
# 'field_name' が指定されていなかったら、 ""を返す。
fields = cgi.keys # <== field nameの配列
# フォームに '......ときに真
cgi.has_key?('field_name')
cgi.include?('field_name')
//}
==== フォームフィールドの値をハッシュとして得る
フォームの値をハッシュとして得るには CGI#params を使います。
//emlist[例][ruby]{
require "cgi"
cgi = CGI.new
params = cgi.params
//}......また CGI#params は毎回同じ Hash オブジェクトを返すので
以下のような使いかたもできます。
//emlist[][ruby]{
cgi.params['new_field_name'] = ["value"] # 新しいパラメータを加える
cgi.params['field_name'] = ["new_value"] # パラメータの値を変え... -
tsort (13.0)
-
tsort はトポロジカルソートと強連結成分に関するモジュールを提供します。
...=== Example
//emlist[][ruby]{
require 'tsort'
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end
{1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
#=> [3, 2, 1, 4]
{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_c......単純な `make' に似たツールは以下のように実装できます。
//emlist[][ruby]{
require 'tsort'
class Make
def initialize
@dep = {}
@dep.default = []
end
def rule(outputs, inputs=[], &block)
triple = [outputs, inputs, block]
outputs.each {|f| @dep[f] = [tripl......each_strongly_connected_component_from(target) {|ns|
if ns.length != 1
fs = ns.delete_if {|n| Array === n}
raise TSort::Cyclic.new("cyclic dependencies: #{fs.join ', '}")
end
n = ns.first
if Array === n
outputs, inputs, block = n
inputs_time =...