90件ヒット
[1-90件を表示]
(0.126秒)
ライブラリ
- ビルトイン (90)
キーワード
- arity (11)
- binding (11)
- curry (11)
- hash (11)
- inspect (11)
- parameters (2)
-
source
_ location (11) -
to
_ s (11) - yield (11)
検索結果
先頭5件
-
Proc
# binding -> Binding (12401.0) -
Proc オブジェクトが保持するコンテキストを Binding オブジェクトで返します。
...
Proc オブジェクトが保持するコンテキストを
Binding オブジェクトで返します。
//emlist[例][ruby]{
def fred(param)
proc {}
end
sample_proc = fred(99)
eval("param", sample_proc.binding) # => 99
//}... -
Proc
# inspect -> String (6201.0) -
self の文字列表現を返します。
...self の文字列表現を返します。
可能なら self を生成したソースファイル名、行番号を含みます。
//emlist[例][ruby]{
p Proc.new {
true
}.to_s
# => "#<Proc:0x0x401a880c@-:3>"
//}... -
Proc
# arity -> Integer (6101.0) -
Proc オブジェクトが受け付ける引数の数を返します。
...
Proc オブジェクトが受け付ける引数の数を返します。
ただし、可変長引数を受け付ける場合、負の整数
-(必要とされる引数の数 + 1)
を返します。
//emlist[例][ruby]{
lambda{ }.arity # => 0
lambda{|| }.arity # => 0
lambd......a{|x| }.arity # => 1
lambda{|*x| }.arity # => -1
lambda{|x, y| }.arity # => 2
lambda{|x, *y| }.arity # => -2
lambda{|(x, y)| }.arity # => 1
lambda{|(x, y), z|}.arity # => 2
//}... -
Proc
# source _ location -> [String , Integer] | nil (6101.0) -
ソースコードのファイル名と行番号を配列で返します。
...nil を返します。
//emlist[例][ruby]{
# /path/to/target.rb を実行
proc {}.source_location # => ["/path/to/target.rb", 1]
proc {}.source_location # => ["/path/to/target.rb", 2]
(eval "proc {}").source_location # => ["(eval)", 1]
method(:p).to_proc.source_location #......=> nil
//}
@see Method#source_location... -
Proc
# to _ s -> String (3101.0) -
self の文字列表現を返します。
...self の文字列表現を返します。
可能なら self を生成したソースファイル名、行番号を含みます。
//emlist[例][ruby]{
p Proc.new {
true
}.to_s
# => "#<Proc:0x0x401a880c@-:3>"
//}... -
Proc
# yield(*arg) -> () (3101.0) -
手続きオブジェクトを実行してその結果を返します。
...くは Proc#lambda? を参照してください。
「===」は when の所に手続きを渡せるようにするためのものです。
//emlist[例][ruby]{
def sign(n)
case n
when lambda{|n| n > 0} then 1
when lambda{|n| n < 0} then -1
else 0
end
end
p sign(-4) #=> -1
p sign(0) #=>......0
p sign(7) #=> 1
//}
また、以下のような syntactic sugar もあります。
//emlist[例][ruby]{
fib = lambda{|n|
case n
when 0 then 0
when 1 then 1
else
fib.(n - 2) + fib.(n - 1)
end
}
fib.(10) # => 55
//}
@param arg 手続きオブジェクトに与える引数を指......定します。
@raise LocalJumpError Procを生成したメソッドからリターンしてしまった場合に発生します。... -
Proc
# curry(arity) -> Proc (101.0) -
Procをカリー化します
...Procをカリー化します
カリー化したProcはいくつかの引数をとります。十分な数の引数が与えられると、元のProcに引数を渡し
て実行し、結果を返します。引数の個数が足りないときは、部分適用したカリー化Procを返します......。
@param 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][3, 4][5] #=> 6
p b.curry(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... -
Proc
# hash -> Integer (101.0) -
self のハッシュ値を返します。
...self のハッシュ値を返します。
Proc オブジェクトの引数の情報を返します。
Proc オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以......引数名を表す Symbol の 2 要素です。
//emlist[][ruby]{
prc = proc{|x, y=42, *other|}
p prc.parameters # => x], [:opt, :y], [:rest, :other
prc = lambda{|x, y=42, *other|}
p prc.parameters # => x], [:opt, :y], [:rest, :other
prc = proc{|x, y=42, *other|}
p prc.parameters(lambda: true) #... -
Proc
# parameters(lambda: nil) -> [object] (101.0) -
Proc オブジェクトの引数の情報を返します。
...Proc オブジェクトの引数の情報を返します。
Proc オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す......い Proc として
扱ったときの引数の情報を返します。
//emlist[例][ruby]{
prc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}
prc.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
//}
//emlist[......lambda: の例][ruby]{
prc = proc{|x, y=42, *other|}
p prc.parameters # => x], [:opt, :y], [:rest, :other
prc = lambda{|x, y=42, *other|}
p prc.parameters # => x], [:opt, :y], [:rest, :other
prc = proc{|x, y=42, *other|}
p prc.parameters(lambda: true) # => x], [:opt, :y], [:rest, :other
prc = lam...