るりまサーチ

最速Rubyリファレンスマニュアル検索!
412件ヒット [1-100件を表示] (0.116秒)

別のキーワード

  1. _builtin to_proc
  2. _builtin proc
  3. proc curry
  4. httpserver mount_proc
  5. readline completion_proc

検索結果

<< 1 2 3 ... > >>

Proc#call(*arg) -> () (36114.0)

手続きオブジェクトを実行してその結果を返します。

...を実行してその結果を返します。

引数の渡され方はオブジェクトの生成方法によって異なります。
詳しくは Proc#lambda? を参照してください。

「===」は when の所に手続きを渡せるようにするためのものです。

//emlist[例][ruby...
...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#<<(callable) -> Proc (21290.0)

self と引数を合成した Proc を返します。

...成した Proc を返します。

戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を callable に渡して呼び出し、
その戻り値を self に渡して呼び出した結果を返します。

Proc
#>> とは呼...
...が逆になります。

@param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//emlist[例][ruby]{
f = proc { |x| x * x }
g = proc { |x| x + x }

# (3 + 3) * (3 + 3)
p (f << g).call(3) # => 36
//}

//emlist[call を定義したオブジェクト...
...例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = proc { |data| puts "word count: #{data.size}" } << WordScanner << File.method(:read)
pipeline.call('testfile') # => word count: 4
//}

@se...

Proc#>>(callable) -> Proc (21290.0)

self と引数を合成した Proc を返します。

...成した Proc を返します。

戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を self に渡して呼び出し、
その戻り値を callable に渡して呼び出した結果を返します。

Proc
#<< とは呼...
...が逆になります。

@param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//emlist[例][ruby]{
f = proc { |x| x * x }
g = proc { |x| x + x }

# (3 * 3) + (3 * 3)
p (f >> g).call(3) # => 18
//}

//emlist[call を定義したオブジェクト...
...を渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = proc { |fname| File.read(fname) } >> WordScanner >> method(:p)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]...

Proc#ruby2_keywords -> proc (21210.0)

Marks the proc as passing keywords through a normal argument splat. This should only be called on procs that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the proc such that if the proc is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the proc to other methods.

...Marks the proc as passing keywords through a normal argument splat. This
should only be called on procs that accept an argument splat (`*args`)
but not explicit keywords or a keyword splat. It marks the proc such
that if the proc is called with keyword arguments, the final hash
argument is marked...
...rgument splat to another method call, and that
method call does not include explicit keywords or a keyword splat, the
final element is interpreted as keywords. In other words, keywords will
be passed through the proc to other methods.

This should only be used for procs that delegate keywords to an...
...backwards compatibility. As it does not exist in Ruby versions
before 2.7, check that the proc responds to this method before calling
it. Also, be aware that if this method is removed, the behavior of the
proc
will change so that it does not pass through keywords.

//emlist[][ruby]{
module Mod
fo...

Proc#lambda? -> bool (21175.0)

手続きオブジェクトの引数の取扱が厳密であるならば true を返します。

...list[例][ruby]{
# lambda で生成した Proc オブジェクトでは true
lambda{}.lambda? # => true
# proc で生成した Proc オブジェクトでは false
proc
{}.lambda? # => false
# Proc.new で生成した Proc オブジェクトでは false
Proc
.new{}.lambda? # => false

# 以下、lam...
...bda?が偽である場合
# 余分な引数を無視する
proc
{|a,b| [a,b]}.call(1,2,3) # => [1,2]
# 足りない引数には nil が渡される
proc
{|a,b| [a,b]}.call(1) # => [1, nil]
# 配列1つだと展開される
proc
{|a,b| [a,b]}.call([1,2]) # => [1,2]
# lambdaの場合これらはすべて...
...生成される Proc は lambda? が偽となる
def n(&b) b.lambda? end
n {} # => false

# &が付いた実引数によるものは、lambda?が元の Procオブジェクトから
# 引き継がれる
lambda(&lambda {}).lambda? #=> true
proc
(&lambda {}).lambda? #=> true
Proc
.new(&lambda {}).l...

絞り込み条件を変える

Proc#===(*arg) -> () (21014.0)

手続きオブジェクトを実行してその結果を返します。

...を実行してその結果を返します。

引数の渡され方はオブジェクトの生成方法によって異なります。
詳しくは Proc#lambda? を参照してください。

「===」は when の所に手続きを渡せるようにするためのものです。

//emlist[例][ruby...
...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#[](*arg) -> () (21014.0)

手続きオブジェクトを実行してその結果を返します。

...を実行してその結果を返します。

引数の渡され方はオブジェクトの生成方法によって異なります。
詳しくは Proc#lambda? を参照してください。

「===」は when の所に手続きを渡せるようにするためのものです。

//emlist[例][ruby...
...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#yield(*arg) -> () (21014.0)

手続きオブジェクトを実行してその結果を返します。

...を実行してその結果を返します。

引数の渡され方はオブジェクトの生成方法によって異なります。
詳しくは Proc#lambda? を参照してください。

「===」は when の所に手続きを渡せるようにするためのものです。

//emlist[例][ruby...
...when 0 then 0
when 1 then 1
else
fib.(n - 2) + fib.(n - 1)
end
}
fib.(10) # => 55
//}



@param arg 手続きオブジェクトに与える引数を指定します。

@raise LocalJumpError Procを生成したメソッドからリターンしてしまった場合に発生します。...

Symbol#to_proc -> Proc (6285.0)

self に対応する Proc オブジェクトを返します。

...self に対応する Proc オブジェクトを返します。

生成される Proc オブジェクトを呼びだす(Proc#call)と、
Proc
#callの第一引数をレシーバとして、 self という名前のメソッドを
残りの引数を渡して呼びだします。


//emlist[明示的に...
...呼ぶ例][ruby]{
:to_i.to_proc["ff", 16] # => 255 ← "ff".to_i(16)と同じ
//}

//emlist[暗黙に呼ばれる例][ruby]{
# メソッドに & とともにシンボルを渡すと
# to_proc が呼ばれて Proc 化され、
# それがブロックとして渡される。
(1..3).collect(&:to_s) #...
...=> ["1", "2", "3"]
(1..3).select(&:odd?) # => [1, 3]
//}

@see d:spec/call#block...
...対応する Proc オブジェクトを返します。

生成される Proc オブジェクトを呼びだす(Proc#call)と、
Proc
#callの第一引数をレシーバとして、 self という名前のメソッドを
残りの引数を渡して呼びだします。

生成される Proc オブジ...
...by]{
:object_id.to_proc.lambda? # => true
//}

//emlist[明示的に呼ぶ例][ruby]{
:to_i.to_proc["ff", 16] # => 255 ← "ff".to_i(16)と同じ
//}

//emlist[暗黙に呼ばれる例][ruby]{
# メソッドに & とともにシンボルを渡すと
# to_proc が呼ばれて Proc 化され、
# そ...
...れがブロックとして渡される。
(1..3).collect(&:to_s) # => ["1", "2", "3"]
(1..3).select(&:odd?) # => [1, 3]
//}

@see d:spec/call#block...

WEBrick::HTTPServer#mount_proc(dir, proc) -> () (6266.0)

サーバ上のディレクトリ dir にリクエストを処理する Proc オブジェクト proc を対応させます。

...のディレクトリ dir にリクエストを処理する Proc オブジェクト proc を対応させます。

@param dir ディレクトリをあらわす文字列を指定します。

@param proc リクエストを処理する Proc オブジェクトを指定します。
WEBrick::...
...HTTPResponse オブジェクトと WEBrick::HTTPRequest
オブジェクトを引数として proc.call(request, response) の引数の順で呼び出されます。

@raise WEBrick::HTTPServerError proc も指定されずブロックも与えられない場合に発生します。...

絞り込み条件を変える

Method#to_proc -> Proc (6253.0)

self を call する Proc オブジェクトを生成して返します。

...self を call する Proc オブジェクトを生成して返します。

//emlist[例][ruby]{
class Foo
def foo
"foo"
end
end

m = Foo.new.method(:foo) # => #<Method: Foo#foo>
pr = m.to_proc # => #<Proc:0x007f874d026008 (lambda)>
pr.call # => "foo"
//}...
<< 1 2 3 ... > >>