るりまサーチ

最速Rubyリファレンスマニュアル検索!
200件ヒット [1-100件を表示] (0.085秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:p[x] > クラス:Proc[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dh p
  5. rsa p

キーワード

検索結果

<< 1 2 > >>

Proc#to_proc -> self (9109.0)

self を返します。

...self を返します。

//emlist[例][ruby]{
p
r = proc {}
p
pr == pr.to_proc # => true
//}...

Proc#parameters(lambda: nil) -> [object] (6127.0)

Proc オブジェクトの引数の情報を返します。

...Proc オブジェクトの引数の情報を返します。

Proc
オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す...
...Symbol の 2 要素です。

: :req
必須の引数
: :opt
デフォルト値が指定されたオプショナルな引数
: :rest
* で指定された残りすべての引数
: :keyreq
必須のキーワード引数
: :key
デフォルト値が指定されたオプショナルなキーワー...
...

@param lambda true なら lambda として扱ったとき、false なら lambda ではない Proc として
扱ったときの引数の情報を返します。

//emlist[例][ruby]{
p
rc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}
p
rc.parameters #=> x], [:opt, :y], [:...

Proc#inspect -> String (6109.0)

self の文字列表現を返します。

...self の文字列表現を返します。

可能なら self を生成したソースファイル名、行番号を含みます。

//emlist[例][ruby]{
p
Proc.new {
true
}.to_s

# => "#<Proc:0x0x401a880c@-:3>"
//}...

Proc#parameters -> [object] (6103.0)

Proc オブジェクトの引数の情報を返します。

...Proc オブジェクトの引数の情報を返します。

Proc
オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す...
...Symbol の 2 要素です。

: :req
必須の引数
: :opt
デフォルト値が指定されたオプショナルな引数
: :rest
* で指定された残りすべての引数
: :keyreq
必須のキーワード引数
: :key
デフォルト値が指定されたオプショナルなキーワー...
...ck
& で指定されたブロック引数


//emlist[例][ruby]{
p
rc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}
p
rc.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
//}


@see Method#parameters, UnboundMethod#parameters...

Proc#curry -> Proc (3223.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#curry(arity) -> Proc (3223.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#>>(callable) -> Proc (3115.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 を定義した...
...anner
def self.call(str)
str.scan(/\w+/)
end
end

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

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

@see Method#<<, Method#>>...

Proc.new -> Proc (3115.0)

ブロックをコンテキストとともにオブジェクト化して返します。

....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
p
r = Proc.new
p
r.call(1)
end
foo {|arg| p arg }
# => 1
//}

これは以下と同じです。

//emlist[例][ruby]{
def foo
yield(1)
end
foo {|arg| p arg }
# => 1
//}

呼び出し元のメソッドがブロックを伴...

Proc.new { ... } -> Proc (3115.0)

ブロックをコンテキストとともにオブジェクト化して返します。

....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
p
r = Proc.new
p
r.call(1)
end
foo {|arg| p arg }
# => 1
//}

これは以下と同じです。

//emlist[例][ruby]{
def foo
yield(1)
end
foo {|arg| p arg }
# => 1
//}

呼び出し元のメソッドがブロックを伴...

Proc#<<(callable) -> Proc (3109.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 を定義した...
...anner
def self.call(str)
str.scan(/\w+/)
end
end

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

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

@see Method#<<, Method#>>...

絞り込み条件を変える

Proc.new { ... } -> Proc (3109.0)

ブロックをコンテキストとともにオブジェクト化して返します。

...を行ったときに発生します。

//emlist[][ruby]{
p
r = Proc.new {|arg| p arg }
p
r.call(1) # => 1
//}

//emlist[][ruby]{
Proc
.new # => -e:1:in `new': tried to create Proc object without a block (ArgumentError)
//}

Proc
.new は、Proc#initialize が定義されていれば
オブジェクト...
...の初期化のためにこれを呼び出します。このことを
除けば、Kernel.#proc と同じです。...

Proc#ruby2_keywords -> proc (3103.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.

...e 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 sp...
...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.

This should only be used for procs that delegate key...
...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 versions
before 2.7, check that the proc responds to this method before calling
it. Als...

Proc#hash -> Integer (3027.0)

self のハッシュ値を返します。

...self のハッシュ値を返します。



Proc
オブジェクトの引数の情報を返します。

Proc
オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以...
...emlist[][ruby]{
p
rc = proc{|x, y=42, *other|}
p
prc.parameters # => x], [:opt, :y], [:rest, :other
p
rc = lambda{|x, y=42, *other|}
p
prc.parameters # => x], [:opt, :y], [:rest, :other
p
rc = proc{|x, y=42, *other|}
p
prc.parameters(lambda: true) # => x], [:opt, :y], [:rest, :other
p
rc = lambda{|x,...
...y=42, *other|}
p
prc.parameters(lambda: false) # => x], [:opt, :y], [:rest, :other
//}...
<< 1 2 > >>