モジュール
- Open3 (48)
-
RubyVM
:: AbstractSyntaxTree (10)
キーワード
- << (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 3
. 0 . 0 (5) - OCSP (12)
- Queue (12)
-
add
_ row (12) - binwrite (12)
- deconstruct (3)
-
deconstruct
_ keys (9) -
enum
_ for (24) - new (12)
- of (10)
-
pipeline
_ rw (24) -
pipeline
_ w (24) - rss (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12) -
to
_ enum (24) - パターンマッチ (12)
検索結果
先頭5件
-
CSV
# puts(row) -> self (15137.0) -
自身に row を追加します。
..."csv"
File.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
CSV.open("test.csv", "a") do |csv|
csv.puts(["5", "saburo", "kondo", "34"])
end
print File.read("test.csv")
# => id,first name,last name,age
# 1,taro,tanaka,20......id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
CSV.open("test.csv", "a") do |csv|
row = CSV::Row.new(["id", "first name", "last name", "age"], ["5", "saburo", "kondo", "34"])
csv.add_row(row)
end
print File.read("test.csv")
# => "id", first nam... -
Range
. new(first , last , exclude _ end = false) -> Range (147.0) -
first から last までの範囲オブジェクトを生成して返しま す。
...
first から last までの範囲オブジェクトを生成して返しま
す。
exclude_end が真ならば終端を含まない範囲オブジェクトを生
成します。exclude_end 省略時には終端を含みます。
@param first 最初のオブジェクト
@param last 最後のオブ......ジェクト
@param exclude_end 真をセットした場合終端を含まない範囲オブジェクトを生成します
@raise ArgumentError first <=> last が nil の場合に発生します
//emlist[例: 整数の範囲オブジェクトの場合][ruby]{
Range.new(1, 10) # => 1..10
Rang......oday, Date.today >> 1).each {|d| puts d }
# => 2017-09-16
# 2017-09-17
# ...
# 2017-10-16
//}
//emlist[例: IPアドレスの範囲オブジェクトの場合][ruby]{
require 'ipaddr'
Range.new(IPAddr.new("192.0.2.1"), IPAddr.new("192.0.2.3")).each {|ip| puts ip}
# => 192.0.2.1
# 192.0.... -
ruby 1
. 6 feature (120.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...p /a#{Regexp.quote("#")}b/x =~ "ab"
=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-03-01) [i586-linux]
"#"
0
=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-07-30) [i586-linux]......p /a#{Regexp.quote("\t")}b/x =~ "ab"
=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-03-01) [i586-linux]
"\t"
0
=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-05-04) [i586-linux]......シグナルを送らないと終了しない不具合が修正さ
れました。((<ruby-bugs-ja:PR#223>))
trap(:TERM, "EXIT")
END{
puts "exit"
}
Thread.start { Thread.stop }
sleep
: 2002-04-17: Regexp#inspect
((<ruby-bugs-ja:PR#222>))
p %r{\/}
=> ruby 1... -
Open3
. # pipeline _ rw(*cmds) {|first _ stdin , last _ stdout , wait _ thrs| . . . } -> () (119.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事も最後のコマンドの標準出力を受けとる事も できます。
...列で返します。
例:
require "open3"
Open3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs|
stdin.puts "foo"
stdin.puts "bar"
stdin.puts "baz"
# sortコマンドにEOFを送る。
stdin.close
# stdinに渡した文字列をsortコマンドが... -
Open3
. # pipeline _ w(*cmds) {|first _ stdin , wait _ thrs| . . . } -> () (107.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事ができます。
...た場合は最初に実行するコマンドの標準入力、
実行したプロセスを待つためのスレッドの配列を配列で返します。
例:
require "open3"
Open3.pipeline_w("bzip2 -c", :out=>"/tmp/hello.bz2") {|w, ts|
w.puts "hello"
}
@see Open3.#popen3... -
rss (78.0)
-
RSS を扱うためのライブラリです。
....each do |fname|
feed = nil
begin
feed = RSS::Parser.parse(File.read(fname), false)
rescue RSS::Error
end
if feed.nil?
puts "#{fname}はRSS 0.9x/1.0/2.0, Atom 1.0のいずれでもありません。"
else
print_items(feed)
end
end
あとはprint_item......: /rss/channel/image要素
ここでは、itemsを使って各項目を表示します。
def print_items(feed)
feed.items.each do |item|
puts "#{item.title} : #{item.description}"
end
end
これは、RSSフィードに対してはうまく動きますが、Atomフィードに......(["My site", ...]など)
rss.channel.dc_titles.first.value == rss.channel.dc_title
# => true
# 厳密にはこう
first_title = rss.channel.dc_titles.first
first_title = first_title.value if first_title
first_title == rss.channel.dc_title... -
OpenSSL
:: OCSP (54.0) -
OCSP(Online Certificate Status Protocol)を取り扱うための モジュールです。OCSP は 2560 で定義されています。
....new(httpres.body)
puts "Response status: #{res.status_string}"
exit if res.status != OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
basic_resp = res.basic
raise "nonce error" unless [-1, 1].include?(req.check_nonce(basic_resp))
unless basic_resp.verify([], store)
puts "verify response......tupd, exts = basic_resp.status.first
STATUS2MESSAGE = {
OpenSSL::OCSP::V_CERTSTATUS_GOOD => "OK",
OpenSSL::OCSP::V_CERTSTATUS_REVOKED => "REVOKED",
OpenSSL::OCSP::V_CERTSTATUS_UNKNOWN => "UNKNOWN",
}
puts "status: #{STATUS2MESSAGE[status]}"
puts "reason: #{reason}" if status......== OpenSSL::OCSP::V_CERTSTATUS_REVOKED
puts "revoked time: #{revtime}" if status == OpenSSL::OCSP::V_CERTSTATUS_REVOKED
puts "response update: #{thisupd}"
puts "response next update: #{nextupd}"
puts "extensions: "
exts.each{|ext| p ext}... -
Date
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (48.0) -
パターンマッチに使用する名前と値の Hash を返します。
...3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end
#=> "first Wednesday of the month" が出力される
case d
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"
end
#=> "working......day in month 10" が出力される
# クラスのチェックと組み合わせて利用することもできます
if d in Date(wday: 3, day: ..7)
puts "first Wednesday of the month"
end
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Time
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (48.0) -
パターンマッチに使用する名前と値の Hash を返します。
...3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end
#=> "first Wednesday of the month" が出力される
case t
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"
end
#=> "working......day in month 10" が出力される
# クラスのチェックと組み合わせて利用することもできます
if t in Time(wday: 3, day: ..7)
puts "first Wednesday of the month"
end
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
パターンマッチ (48.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...r:} # ネストしてハッシュにマッチして、その値を変数userに代入する
puts "Connect with user '#{user}'"
in connection: {username: }
puts "Connect with user '#{username}'"
else
puts "Unrecognized structure of config"
end
# "Connect with user 'admin'" と出力
//}
一方......n', password: 'abc123'}}
config in {db: {user:}} # もし config の構造が期待したものでなかった場合には、例外が発生する
puts "Connect with user '#{user}'"
# Connect with user 'admin'" と出力
//}
『<expression> in <pattern>』 は 『<expression>; in <pattern>; true;......用できます。
//emlist[][ruby]{
case {name: 'John', friends: [{name: 'Jane'}, {name: 'Rajesh'}]}
in name:, friends: [{name: first_friend}, *]
"matched: #{first_friend}"
else
"not matched"
end
#=> "matched: Jane"
//}
パターンの残りの部分も同様に変数に束縛できます。......n', password: 'abc123'}}
config => {db: {user:}} # もし config の構造が期待したものでなかった場合には、例外が発生する
puts "Connect with user '#{user}'"
# Connect with user 'admin'" と出力
//}
『<expression> in <pattern>』 は 『<expression>; in <pattern>; true;...