114件ヒット
[1-100件を表示]
(0.014秒)
キーワード
- bigdecimal (12)
- irb (12)
-
net
/ http (12) - openssl (12)
- pp (12)
- prettyprint (12)
- rake (12)
- rss (12)
- shell (6)
- tsort (12)
検索結果
先頭5件
-
prettyprint (6001.0)
-
pretty printing アルゴリズムのためのライブラリです。
...pretty printing アルゴリズムのためのライブラリです。
=== 使い方
pretty printing アルゴリズムは読みやすいインデントと改行を決定するためのアルゴリズムです。
インデントと改行はユーザによって与えられたツリー構造から......作成する必要があります。
* PrettyPrint.new でバッファを生成します。このとき、バッファの幅と改行文字を指定します。
* PrettyPrint#text を使って、文字列を適宜 挿入します。
* PrettyPrint#group を使って子ノードをつくります......も決めます。
* PrettyPrint#breakable を使って改行しても良い場所を指定します。
同じノード内で呼ばれた breakable は、改行するならば全て同時に改行します。
//emlist[][ruby]{
require 'prettyprint'
p2 = PrettyPrint.new('', 10)
s = 'hello'
p2.tex... -
rss (55.0)
-
RSS を扱うためのライブラリです。
...r
end
if feed.nil?
puts "#{fname}はRSS 0.9x/1.0/2.0, Atom 1.0のいずれでもありません。"
else
print_items(feed)
end
end
あとはprint_itemsというメソッドを定義するだけです。
RSS::RDF/RSS::Rss/RSS::Atom::Feed/RSS::Atom::Entryには便利......* RSS::RDF: /rdf:RDF/image要素
* RSS::Rss: /rss/channel/image要素
ここでは、itemsを使って各項目を表示します。
def print_items(feed)
feed.items.each do |item|
puts "#{item.title} : #{item.description}"
end
end
これは、RSSフィードに対して......ードにはdescription要
素がないからです。そこで、AtomフィードもRSSフィードに変えて
扱うことにします。
def print_items(feed)
convert_to_rss10(feed).items.each do |item|
puts "#{item.title} : #{item.description}"
end
end
convert_to_rss10は以... -
pp (37.0)
-
オブジェクトなどを見やすく出力するためのライブラリです。
...か?
p による pretty-print されてない出力:
#<PP:0x81a0d10 @stack=[], @genspace=#<Proc:0x81a0cc0>, @nest=[0], @newline="\n",
@buf=#<PrettyPrint::Group:0x81a0c98 @group=0, @tail=0, @buf=[#<PrettyPrint::Gro
up:0x81a0ba8 @group=1, @tail=0, @buf=[#<PrettyPrint::Text:0x81a0b30 @tail=2, @......wi
dth=1, @text="[">, #<PrettyPrint::Group:0x81a0a68 @group=2, @tail=1, @buf=[#<Pre
ttyPrint::Text:0x81a09f0 @tail=1, @width=1, @text="1">], @singleline_width=1>, #
<PrettyPrint::Text:0x81a0a7c @tail=0, @width=1, @text=",">, #<PrettyPrint::Break
able:0x81a0a2c @group=2, @gensace=#<Proc:0x81a......Print::Group:0x81a09c8 @group=2, @tail=1, @
buf=[#<PrettyPrint::Text:0x81a0950 @tail=1, @width=1, @text="2">], @singleline_w
idth=1>, #<PrettyPrint::Text:0x81a0af4 @tail=0, @width=1, @text="]">], @singleli
ne_width=6>], @singleline_width=6>, @sharing_detection=false>
pp による pretty-print... -
irb (31.0)
-
irb は Interactive Ruby の略です。 irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
...され、結果が表示されます。
irb(main):001:0> 1+2
3
irb(main):002:0> class Foo
irb(main):003:1> def foo
irb(main):004:2> print 1
irb(main):005:2> end
irb(main):006:1> end
:foo
irb(main):007:0>
また irb コマンドは readline ライブラリにも対応し......-d $DEBUG を true にする (ruby -d と同じ)
-w ruby -w と同じ
-W[level=2] ruby -W と同じ
-r library ruby -r と同じ
-I ruby -I と同じ
-U ruby -U と同じ
-E enc ruby -E と同じ
--ve......T_MODE] = :MY_PROMPT
PROMPT_I, PROMPT_S, PROMPT_C にはフォーマット文字列を指定します。
フォーマット文字列では Kernel.#printf のように
「%」を用いた記法が使えます。
フォーマット文字列で使用可能な記法は以下の通りです。
: %N... -
net
/ http (25.0) -
汎用データ転送プロトコル HTTP を扱うライブラリです。 実装は 2616 に基きます。
...る (GET)
//emlist[例1: GET して 表示するだけ][ruby]{
require 'net/http'
print Net::HTTP.get('www.example.com', '/index.html')
//}
//emlist[例2: URI を使う][ruby]{
require 'net/http'
require 'uri'
print Net::HTTP.get(URI.parse('http://www.example.com/index.html'))
//}
//emlist[例3:......nse
when Net::HTTPSuccess
response
when Net::HTTPRedirection
fetch(response['location'], limit - 1)
else
response.value
end
end
print fetch('http://www.example.org')
//}
より詳しくは Net::HTTPResponse、 Net::HTTPSuccess、
Net::HTTPRedirection を参照してください......t('www.example.com') {|http|
req = Net::HTTP::Get.new('/secret-page.html')
req.basic_auth 'account', 'password'
response = http.request(req)
print response.body
}
//}
=== フォームの値の区切り文字について
POSTで application/x-www-form-urlencoded として複数のフォ... -
shell (25.0)
-
Ruby 上で sh/csh のようにコマンドの実行及びフィルタリングを手軽に行うためのライブラリです。
...nless sh.exists?(dir)
sh.mkdir dir
sh.cd(dir) do
f = sh.open("tmpFile", "w")
f.puts "TEST"
f.close
end
print sh.pwd
end
end
==== Example 2:
require 'shell'
sh = Shell.cd("/tmp")
sh.transact do
mkdir "shell-test-1" unless exists?("shel......f.print "TEST\n"
f.close
end
print pwd
end
end
end
==== Example 3: Using Pipe
require 'shell'
sh = Shell.new
sh.cat("/etc/printcap") | sh.tee("tee1") > "tee2"
(sh.cat < "/etc/printcap") | sh.tee("tee11") > "tee12"
sh.cat("/etc/printcap") | sh.......tee("tee1") >> "tee2"
(sh.cat < "/etc/printcap") | sh.tee("tee11") >> "tee12"
==== Example 4:
require 'shell'
sh = Shell.new
print sh.cat("/etc/passwd").head.collect {|line| /keiju/ =~ line }... -
bigdecimal (19.0)
-
bigdecimal は浮動小数点数演算ライブラリです。 任意の精度で 10 進表現された浮動小数点数を扱えます。
...数点数を扱えます。
//emlist[][ruby]{
require 'bigdecimal'
a = BigDecimal("0.123456789123456789")
b = BigDecimal("123456.78912345678", 40)
print a + b # => 0.123456912580245903456789e6
//}
一般的な 10 進数の計算でも有用です。2 進数の浮動小数点演算には微小な......i in (1..10000)
sum = sum + 0.0001
end
print sum # => 0.9999999999999062
//}
//emlist[例2: 0.0001 を 10000 回足す場合。(BigDecimal)][ruby]{
require 'bigdecimal'
sum = BigDecimal("0")
for i in (1..10000)
sum = sum + BigDecimal("0.0001")
end
print sum # => 0.1e1
//}
//emlist[例3: 1.2... -
openssl (7.0)
-
OpenSSL(https://www.openssl.org/) を Ruby から扱うためのライブラリです。
...cer.serial = 1
cer.issuer = issu
cer.subject = sub
cer.sign(key, digest) # <= 署名するのに使う秘密鍵とハッシュ関数
print cer.to_text
===[a:references] 参考文献
* 5246
* Eric Rescorla. SSL and TLS : Designing and Building Secure Systems.
邦訳, Eric Resco... -
rake (7.0)
-
Rake というコマンドラインツールを扱うライブラリです。
...せずにタスクを実行します。
-e, --execute CODE Ruby のコードを実行して終了します。
-p, --execute-print CODE Ruby のコードを実行して結果を表示して終了します。
-E, --execute-continue CODE Ruby のコードを実行し...