別のキーワード
ライブラリ
クラス
- Enumerator (31)
-
Enumerator
:: Yielder (6) - Hash (121)
- Logger (24)
- Method (72)
- Module (24)
- Object (60)
- PrettyPrint (12)
- Proc (207)
-
RubyVM
:: InstructionSequence (36) - String (36)
- Symbol (12)
- Thread (24)
- TracePoint (7)
- UnboundMethod (12)
モジュール
- Enumerable (48)
- Etc (12)
- JSON (24)
- Kernel (121)
- Marshal (48)
- ObjectSpace (48)
- Open3 (12)
- PTY (12)
- Process (92)
-
Rake
:: TaskManager (12) -
RubyVM
:: AbstractSyntaxTree (10) - Signal (24)
キーワード
-
$ CHILD _ STATUS (12) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - << (14)
- === (12)
- >> (14)
- InstructionSequence (12)
- Marshal フォーマット (12)
- Method (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 2
. 1 . 0 (12) -
NEWS for Ruby 2
. 2 . 0 (11) -
NEWS for Ruby 2
. 3 . 0 (10) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 2
. 5 . 0 (8) -
NEWS for Ruby 2
. 6 . 0 (7) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (5) - Proc (12)
- Ruby プログラムの実行 (12)
- Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (12)
- Ruby用語集 (12)
- [] (24)
-
add
_ trace _ func (12) - argv0 (12)
- arity (12)
-
at
_ exit (12) - binding (12)
- call (12)
- check (12)
-
count
_ tdata _ objects (12) -
create
_ rule (12) - curry (46)
- default (24)
-
default
_ proc (12) -
default
_ proc= (12) -
define
_ finalizer (24) -
define
_ method (24) -
define
_ singleton _ method (24) - detect (24)
- disasm (12)
- disassemble (12)
- drb (12)
- dump (24)
- encode (36)
- find (24)
- format (12)
- formatter (12)
- formatter= (12)
- groups (12)
- inspect (12)
- irb (12)
- lambda (18)
- lambda? (12)
-
last
_ status (8) - load (24)
- logger (12)
- new (62)
- nprocessors (12)
- of (22)
- parameters (31)
- pipeline (12)
- pp (12)
-
rb
_ f _ lambda (12) -
rb
_ protect (12) -
rb
_ scan _ args (12) - restore (24)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12) -
ruby 1
. 8 . 3 feature (12) -
ruby 1
. 9 feature (12) -
ruby2
_ keywords (6) -
ruby2
_ keywords _ hash? (6) - send (24)
-
set
_ trace _ func (24) - setproctitle (12)
- shift (9)
- size (12)
-
source
_ location (36) -
to
_ proc (64) -
to
_ s (12) -
trace
_ var (36) - trap (24)
-
undefine
_ finalizer (12) -
untrace
_ var (12) -
values
_ at (12) - wait (12)
- wait2 (12)
- waitpid (12)
- waitpid2 (12)
- yield (12)
- オブジェクト指向スクリプト言語 Ruby リファレンスマニュアル (12)
- クラス/メソッドの定義 (12)
- セキュリティモデル (12)
- メソッド呼び出し(super・ブロック付き・yield) (12)
- 手続きオブジェクトの挙動の詳細 (12)
検索結果
先頭5件
-
Kernel
. # proc -> Proc (15538.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......ない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE......= true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
@raise ArgumentError スタック上にブロ... -
Kernel
. # proc { . . . } -> Proc (15538.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......ない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE......= true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
@raise ArgumentError スタック上にブロ... -
Kernel
. # proc -> Proc (15537.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......ない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE......= true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
@raise ArgumentError スタック上にブロ... -
Kernel
. # proc { . . . } -> Proc (15537.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......ない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE......= true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
@raise ArgumentError スタック上にブロ......与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があ......deprecated; use the proc without lambda instead」
を出力します。
@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。
//emlist[例][ruby]{
def foo &block
lambda(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
===[a:should......では Proc#call)
へジャンプし値を返すには next を使います。break や return ではありません。
//emlist[例][ruby]{
def foo
f = Proc.new{
next 1
2 # この行に到達することはない
}
end
p foo().call #=> 1
//}
===[a:block] Proc オ......deprecated; use the proc without lambda instead」
を出力します。
@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。
//emlist[例][ruby]{
def foo &block
proc(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
===[a:should_... -
Proc
# ruby2 _ keywords -> proc (15308.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......e proc to other methods.
This should only be used for procs that delegate keywords to another
method, and only for backwards compatibility with Ruby versions before
2.7.
This method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby......he 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
foo = ->(meth, *args, &block) do
send(:"do_#{meth}", *args, &block)
end
foo.ruby2_... -
Proc
# to _ proc -> self (15119.0) -
self を返します。
...self を返します。
//emlist[例][ruby]{
pr = proc {}
p pr == pr.to_proc # => true
//}... -
Proc
. new -> Proc (9186.0) -
ブロックをコンテキストとともにオブジェクト化して返します。
...ックを指定しない場合、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生し......ます。
ブロックを指定しなければ、このメソッドを呼び出したメソッドが
ブロックを伴うときに、それを Proc オブジェクトとして生成して返します。
ただし、ブロックを指定しない呼び出しは推奨されていません。呼び......を省略した呼び出しを行ったときに発生します。
//emlist[例][ruby]{
def foo
pr = Proc.new
pr.call(1)
end
foo {|arg| p arg }
# => 1
//}
これは以下と同じです。
//emlist[例][ruby]{
def foo
yield(1)
end
foo {|arg| p arg }
# => 1
//}
呼び出し元のメソッ... -
Proc
. new { . . . } -> Proc (9186.0) -
ブロックをコンテキストとともにオブジェクト化して返します。
...ックを指定しない場合、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生し......ます。
ブロックを指定しなければ、このメソッドを呼び出したメソッドが
ブロックを伴うときに、それを Proc オブジェクトとして生成して返します。
ただし、ブロックを指定しない呼び出しは推奨されていません。呼び......を省略した呼び出しを行ったときに発生します。
//emlist[例][ruby]{
def foo
pr = Proc.new
pr.call(1)
end
foo {|arg| p arg }
# => 1
//}
これは以下と同じです。
//emlist[例][ruby]{
def foo
yield(1)
end
foo {|arg| p arg }
# => 1
//}
呼び出し元のメソッ... -
Proc
# >>(callable) -> Proc (9183.0) -
self と引数を合成した Proc を返します。
...成した Proc を返します。
戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を self に渡して呼び出し、
その戻り値を callable に渡して呼び出した結果を返します。
Proc#<< とは呼......ram 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 Wor......anner
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"]
//}
@see Method#<<, Method#>>... -
Proc
# <<(callable) -> Proc (9177.0) -
self と引数を合成した Proc を返します。
...成した Proc を返します。
戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を callable に渡して呼び出し、
その戻り値を self に渡して呼び出した結果を返します。
Proc#>> とは呼......ram 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 Wor......dScanner
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
//}
@see Method#<<, Method#>... -
Proc
# curry -> Proc (9166.0) -
Procをカリー化します
...Procをカリー化します
カリー化したProcはいくつかの引数をとります。十分な数の引数が与えられると、元のProcに引数を渡し
て実行し、結果を返します。引数の個数が足りないときは、部分適用したカリー化Procを返します......た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,......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) #=> wrong number of arguments (given 1, expected 3+)
b = proc { :foo }
p b.curry[] #=> :foo
//}... -
Proc
# curry(arity) -> Proc (9166.0) -
Procをカリー化します
...Procをカリー化します
カリー化したProcはいくつかの引数をとります。十分な数の引数が与えられると、元のProcに引数を渡し
て実行し、結果を返します。引数の個数が足りないときは、部分適用したカリー化Procを返します......た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,......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) #=> wrong number of arguments (given 1, expected 3+)
b = proc { :foo }
p b.curry[] #=> :foo
//}... -
Proc
# lambda? -> bool (9162.0) -
手続きオブジェクトの引数の取扱が厳密であるならば true を返します。
...さい。
//emlist[例][ruby]{
# lambda で生成した Proc オブジェクトでは true
lambda{}.lambda? # => true
# proc で生成した Proc オブジェクトでは false
proc{}.lambda? # => false
# Proc.new で生成した Proc オブジェクトでは false
Proc.new{}.lambda? # => false......下、lambda?が偽である場合
# 余分な引数を無視する
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...