種類
- インスタンスメソッド (36)
- モジュール (24)
- ライブラリ (24)
- 文書 (12)
クラス
- Array (36)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - NKF (12)
- Observable (12)
-
net
/ http (12) - tsort (12)
検索結果
先頭5件
-
Array
# fetch(nth) -> object (18127.0) -
nth 番目の要素を返します。
...しなかった場合に発生します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end
p a.fetch(10, 999) #=> 999
result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}... -
Array
# fetch(nth) {|nth| . . . } -> object (18127.0) -
nth 番目の要素を返します。
...しなかった場合に発生します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end
p a.fetch(10, 999) #=> 999
result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}... -
Array
# fetch(nth , ifnone) -> object (18127.0) -
nth 番目の要素を返します。
...しなかった場合に発生します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end
p a.fetch(10, 999) #=> 999
result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}... -
net
/ http (48.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:......==== リダイレクトに対応する
以下の例の fetch はリダイレクトに対応しています。
limit 回数以上リダイレクトしたらエラーにします。
//emlist[例][ruby]{
require 'net/http'
require 'uri'
def fetch(uri_str, limit = 10)
# You should choose better exc......nse(URI.parse(uri_str))
case response
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::HTTPRed... -
Observable (42.0)
-
Observer パターンを提供するモジュールです。
...erver"
class Ticker ### Periodically fetch a stock price.
include Observable
def initialize(symbol)
@symbol = symbol
end
def run
last_price = nil
loop do
price = Price.fetch(@symbol)
print "Current price: #{price}\n"
if price !=......y_observers(Time.now, price)
end
sleep 1
end
end
end
class Price ### A mock class to fetch a stock price (60 - 140).
def self.fetch(symbol)
60 + rand(80)
end
end
class Warner ### An abstract observer of Ticker objects.
def init......allback for observer
if price < @limit
print "--- #{time.to_s}: Price below #@limit: #{price}\n"
end
end
end
class WarnHigh < Warner
def update(time, price) # callback for observer
if price > @limit
print "+++ #{time.to_s}: Price above #@limit: #{... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (18.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
...|Array/transpose>)) [new]
追加
: ((<Array#zip|Enumerable/zip>)) [new]
: ((<Enumerable#zip|Enumerable/zip>)) [new]
追加
: ((<Array#fetch|Array/fetch>)) [new]
追加
: ((<Array#insert|Array/insert>)) [new]
追加 ((<ruby-talk:14289>))
(({ary[n,0] = [other,...]})) と同......。
((<ruby-dev:14172>))
== 拡張されたクラス/メソッド(互換性のある変更)
=== 組み込み関数
: ((<組み込み関数/sprintf>)) [new]
"%p" が追加されました。inspect の結果が利用されます。((<RCR#69>))
: ((<組み込み関数/trap>)) [compat]
あ......e Twister|URL:http://www.math.keio.ac.jp/~matumoto/mt.html>))
を使用するようになりました。
: ((<組み込み関数/sprintf>))('%u') [compat]
sprintf の '%u' で、最上位ビットの繰り返しをあらわす ".." は、付加
されないようになりました。((<ruby... -
NKF (12.0)
-
nkf(Network Kanji code conversion Filter, https://osdn.net/projects/nkf/) を Ruby から使うためのモジュールです。
...の例です。
//emlist[例][ruby]{
#!/usr/local/bin/ruby
require 'nkf'
opt = ''
opt = ARGV.shift if ARGV[0][0] == ?-
while line = ARGF.gets
print NKF.nkf(opt, line)
end
//}
以下は、漢字コード判別コマンドの例です。
//emlist[例][ruby]{
#!/usr/local/bin/ruby
require 'nkf......> "ASCII",
NKF::UNKNOWN => "UNKNOWN",
}
while file = ARGV.shift
str = open(file) {|io| io.gets(nil) }
printf "%-10s ", file
if str.nil?
puts "EMPTY"
else
puts CODES.fetch(NKF.guess(str))
end
end
//}
=== オプション文字列
-b 入力がバッファリングされる(... -
tsort (12.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_co......ll
end
end
}
end
def tsort_each_child(node, &block)
@dep[node].each(&block)
end
include TSort
end
def command(arg)
print arg, "\n"
system arg
end
m = Make.new
m.rule(%w[t1]) { command 'date > t1' }
m.rule(%w[t2]) { command 'date > t2' }
m.rule(%w[t3]) { command '...