種類
- インスタンスメソッド (118)
- クラス (22)
クラス
- Array (19)
- BasicObject (11)
- String (11)
- Time (33)
モジュール
- Enumerable (44)
検索結果
先頭5件
-
Time
# to _ i -> Integer (18115.0) -
起算時からの経過秒数を整数で返します。
...起算時からの経過秒数を整数で返します。
//emlist[][ruby]{
t = Time.local(2000,1,2,3,4,5,6)
p t # => 2000-01-02 03:04:05 +0900
p "%10.6f" % t.to_f # => "946749845.000006"
p t.to_i # => 946749845
p t.tv_sec # => 946749845
//}... -
Time
# tv _ sec -> Integer (3015.0) -
起算時からの経過秒数を整数で返します。
...起算時からの経過秒数を整数で返します。
//emlist[][ruby]{
t = Time.local(2000,1,2,3,4,5,6)
p t # => 2000-01-02 03:04:05 +0900
p "%10.6f" % t.to_f # => "946749845.000006"
p t.to_i # => 946749845
p t.tv_sec # => 946749845
//}... -
Array
# pack(template) -> String (188.0) -
配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。
...cd"].pack("u") # => "$86)C9```\n"
["a"*45].pack("u") # => "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n"
["a"*46].pack("u") # => "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n"
["abcdefghi"].pack("u6") # => "&86)C9&5F\n#9VAI\n"
//}
: U......[82, 117, 98, 121].pack("c*") # => "Ruby"
s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"
[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"
[82, 117, 98, 121].inject("") {|s, c| s << c} # => "Ruby"
//}
: 文字列を数値(文字コード)の配列に変換......byname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"
"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}
: sockaddr_in 構造体
//emlist[][ruby]{
require 'socket'
[Socket::AF_INET,
Socket.getservbyname('echo')... -
Array
# pack(template , buffer: String . new) -> String (188.0) -
配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。
...cd"].pack("u") # => "$86)C9```\n"
["a"*45].pack("u") # => "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n"
["a"*46].pack("u") # => "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n"
["abcdefghi"].pack("u6") # => "&86)C9&5F\n#9VAI\n"
//}
: U......[82, 117, 98, 121].pack("c*") # => "Ruby"
s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"
[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"
[82, 117, 98, 121].inject("") {|s, c| s << c} # => "Ruby"
//}
: 文字列を数値(文字コード)の配列に変換......byname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"
"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}
: sockaddr_in 構造体
//emlist[][ruby]{
require 'socket'
[Socket::AF_INET,
Socket.getservbyname('echo')... -
String
# unpack(template) -> Array (188.0) -
Array#pack で生成された文字列を テンプレート文字列 template にしたがってアンパックし、 それらの要素を含む配列を返します。
...cd"].pack("u") # => "$86)C9```\n"
["a"*45].pack("u") # => "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n"
["a"*46].pack("u") # => "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n"
["abcdefghi"].pack("u6") # => "&86)C9&5F\n#9VAI\n"
//}
: U......[82, 117, 98, 121].pack("c*") # => "Ruby"
s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"
[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"
[82, 117, 98, 121].inject("") {|s, c| s << c} # => "Ruby"
//}
: 文字列を数値(文字コード)の配列に変換......byname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"
"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}
: sockaddr_in 構造体
//emlist[][ruby]{
require 'socket'
[Socket::AF_INET,
Socket.getservbyname('echo')... -
Process
:: Status (26.0) -
プロセスの終了ステータスを表すクラスです。 メソッド Process.#wait2 などの返り値として使われます。
...topped by signal #{$?.stopsig}"
when $?.exited?
p "child #{$?.pid} exited normally. status=#{$?.exitstatus}"
else
p "unknown status %#x" % $?.to_i
end
SIGCHLD を trap する例
trap(:SIGCHLD) {|sig|
puts "interrupted by signal #{sig} at #{caller[1]}"
# 複数の子プロ......stopsig}"
when $?.exited?
puts " child #{$?.pid} exited normally. status=#{$?.exitstatus}"
else
p "unknown status %#x" % $?.to_i
end
end
}
p pid1 = fork { sleep 1; exit }
p pid2 = fork { loop { sleep } } # signal を待つための sleep
begin
Pr... -
BasicObject
# method _ missing(name , *args) -> object (20.0) -
呼びだされたメソッドが定義されていなかった時、Rubyインタプリタがこのメソッド を呼び出します。
...s =~ /\Afind_(\d+)_in\z/
if @data[lang]
p @data[lang][$1.to_i]
else
raise "#{lang} unknown"
end
else
super
end
end
end
dic = Foo.new({:English => %w(zero one two), :Esperanto => %w(nulo unu du)})
dic.find_2_in :Esperanto #=> "du"
//}
[注意] こ... -
Enumerable
# max _ by -> Enumerator (20.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...aram n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #......) # normal distribution
}
# a is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
#=> *
# ***
# ******
# ***********
# ******************
# *****************************
# ***********************************... -
Enumerable
# max _ by {|item| . . . } -> object | nil (20.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...aram n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #......) # normal distribution
}
# a is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
#=> *
# ***
# ******
# ***********
# ******************
# *****************************
# ***********************************... -
Enumerable
# max _ by(n) -> Enumerator (20.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...aram n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #......) # normal distribution
}
# a is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
#=> *
# ***
# ******
# ***********
# ******************
# *****************************
# ***********************************...