114件ヒット
[1-100件を表示]
(0.058秒)
別のキーワード
クラス
- Array (18)
- OptionParser (72)
- Proc (24)
キーワード
- curry (24)
- summarize (24)
-
summary
_ indent (12) -
summary
_ indent= (12) -
summary
_ width (12) -
summary
_ width= (12)
検索結果
先頭5件
-
Array
# sum(init=0) -> object (21239.0) -
要素の合計を返します。例えば [e1, e2, e3].sum は init + e1 + e2 + e3 を返します。
...[e1, e2, e3].sum は init + e1 + e2 + e3 を返します。
ブロックが与えられた場合、加算する前に各要素にブロックが適用されます。
配列が空の場合、initを返します。
//emlist[例][ruby]{
[].sum #=> 0
[].sum(0.0)......[1, 2, 3].sum #=> 6
[3, 5.5].sum #=> 8.5
[2.5, 3.0].sum(0.0) {|e| e * e } #=> 15.25
[Object.new].sum #=> TypeError
//}
配列の平均値は以下のように求められます。
//emlist[例][ruby]{
mean = ary.sum(0.0) / ary.length
/......。
//emlist[例][ruby]{
["a", "b", "c"].sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}
しかし、文字列の配列や配列の配列の場合 Array#join や Array#flatten の方が Array#sum よりも高速です。
//emlist[例][ruby]{
["a", "b", "c"].joi... -
Array
# sum(init=0) {|e| expr } -> object (21239.0) -
要素の合計を返します。例えば [e1, e2, e3].sum は init + e1 + e2 + e3 を返します。
...[e1, e2, e3].sum は init + e1 + e2 + e3 を返します。
ブロックが与えられた場合、加算する前に各要素にブロックが適用されます。
配列が空の場合、initを返します。
//emlist[例][ruby]{
[].sum #=> 0
[].sum(0.0)......[1, 2, 3].sum #=> 6
[3, 5.5].sum #=> 8.5
[2.5, 3.0].sum(0.0) {|e| e * e } #=> 15.25
[Object.new].sum #=> TypeError
//}
配列の平均値は以下のように求められます。
//emlist[例][ruby]{
mean = ary.sum(0.0) / ary.length
/......。
//emlist[例][ruby]{
["a", "b", "c"].sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}
しかし、文字列の配列や配列の配列の場合 Array#join や Array#flatten の方が Array#sum よりも高速です。
//emlist[例][ruby]{
["a", "b", "c"].joi... -
OptionParser
# summary _ indent -> String (12213.0) -
サマリを表示する時のインデントを文字列で返します。
...例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
opts.summary_indent # => " "
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
opts.summary_ind......ent = " "
opts.summary_indent # => " "
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
//}... -
OptionParser
# summary _ indent=(indent) (12213.0) -
サマリを表示する時のインデントを文字列で指定します。
...例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
opts.summary_indent # => " "
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
opts.summary_ind......ent = " " # => " "
opts.summary_indent # => " "
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
//}... -
OptionParser
# summary _ width -> Integer (12213.0) -
サマリを表示するときの幅を整数で返します。
...ist[例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
opts.summary_width # => 32
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
opts.summary_width =......8
opts.summary_width # =>8
opts.summarize
# => [" -i\n", " --init\n", " -u\n", " --update\n", " -h\n", " --help\n"]
//}... -
OptionParser
# summary _ width=(width) (12213.0) -
サマリを表示するときの幅を整数で指定します。
...ist[例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
opts.summary_width # => 32
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
opts.summary_width =......8 # => 8
opts.summary_width # => 8
opts.summarize
# => [" -i\n", " --init\n", " -u\n", " --update\n", " -h\n", " --help\n"]
//}... -
OptionParser
# summarize(to = [] , width = self . summary _ width , max = width - 1 , indent= self . summary _ indent) -> () (6513.0) -
サマリを指定された to へと加えていきます。
...ます。
//emlist[例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
opts.summarize(["description\n"], 10... -
OptionParser
# summarize(to = [] , width = self . summary _ width , max = width - 1 , indent= self . summary _ indent) {|line| . . . } -> () (6513.0) -
サマリを指定された to へと加えていきます。
...ます。
//emlist[例][ruby]{
require "optparse"
opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end
opts.summarize
# => [" -i, --init\n", " -u, --update\n", " -h, --help\n"]
opts.summarize(["description\n"], 10... -
Proc
# curry -> Proc (6173.0) -
Procをカリー化します
...aram arity 引数の個数を指定します
@return カリー化したProcオブジェクトを返します
//emlist[例][ruby]{
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
p b.curry[1][2][3] #=> 6
p b.curry[1, 2][3, 4] #=> 6
p b.curry(5)[1][2][3][4][5] #=> 6
p b.curry(5)[1, 2......ry(1)[1] #=> 1
b = proc {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.sum }
p b.curry[1][2][3] #=> 6
p b.curry[1, 2][3, 4] #=> 10
p b.curry(5)[1][2][3][4][5] #=> 15
p b.curry(5)[1, 2][3, 4][5] #=> 15
p b.curry(1)[1] #=> 1
b = lambda {|x, y, z| (x||0) + (y......b.curry[1][2][3] #=> 6
p b.curry[1, 2][3, 4] #=> wrong number of arguments (given 4, expected 3)
p b.curry(5) #=> wrong number of arguments (given 5, expected 3)
p b.curry(1) #=> wrong number of arguments (given 1, expected 3)
b = lambda {|x, y, z, *...