るりまサーチ

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

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. kernel p
  5. dsa p

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Enumerator::Yielder#yield(*object) -> () (21126.0)

Enumerator.new で使うメソッドです。

...ブジェクトの each メソッドを呼ぶと
Enumerator::Yielder オブジェクトが渡されたブロックが実行され、
ブロック内の yield メソッドが呼ばれるたびに each に渡された
ブロックが yield メソッドに渡された値とともに繰り返されま...
...す。

//emlist[例][ruby]{
enum = Enumerator.new do |y|
y.yield 1, 2, 3
end

enum.each do |x, y, z|
p
[x, y, z]
end
# => [1, 2, 3]
//}...

Proc#yield(*arg) -> () (18120.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
s...
...when 0 then 0
when 1 then 1
else
fib.(n - 2) + fib.(n - 1)
end
}
fib.(10) # => 55
//}



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

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

Enumerator::Yielder#to_proc -> Proc (9213.0)

Enumerator.new で使うメソッドです。

...Enumerator.new で使うメソッドです。

引数を Enumerator::Yielder#yield に渡す Proc を返します。
これは Enumerator::Yielder オブジェクトを他のメソッドにブロック引数と
して直接渡すために使えます。

//emlist[例][ruby]{
text = <<-END
Hello
...
...んにちは
END

enum = Enumerator.new do |y|
text.each_line(&y)
end

enum.each do |line|
p
line
end
# => "Hello\n"
# "こんにちは\n"
//}...

Object#to_proc -> Proc (6213.0)

オブジェクトの Proc への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

...オブジェクトの Proc への暗黙の変換が必要なときに内部で呼ばれます。
デフォルトでは定義されていません。

説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要...
...に応じてサブクラスで定義すべきものです。

//emlist[][ruby]{
def doing
yield

end

class Foo
def to_proc
P
roc.new{p 'ok'}
end
end

it = Foo.new
doing(&it) #=> "ok"
//}...

Enumerator#peek_values -> Array (6161.0)

Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。

...StopIteration 例外を発生します。

このメソッドは Enumerator#next_values と同様
yield


yield
nil
を区別するために使えます。

//emlist[例][ruby]{
o = Object.new
def o.each
yield

yield
1
yield
1, 2
end
e = o.to_enum
p
e.peek_values #=> []
e.next
p
e.peek...
..._values #=> [1]
p
e.peek_values #=> [1]
e.next
p
e.peek_values #=> [1, 2]
e.next
p
e.peek_values # raises StopIteration
//}

@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values...

絞り込み条件を変える

Enumerable#compact -> Array (6125.0)

self から nil を取り除いた配列を生成して返します。

...self から nil を取り除いた配列を生成して返します。

//emlist[][ruby]{
def with_nils
yield
1
yield
2
yield
nil
yield
3
end

to_enum(:with_nils).compact # => [1, 2, 3]
//}

@see Array#compact...

Object#tap {|x| ... } -> self (6107.0)

self を引数としてブロックを評価し、self を返します。

...目的です。

//emlist[][ruby]{
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
//}

@see Object#yield_self...

Pathname#each_entry {|pathname| ... } -> nil (3123.0)

Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。

....to_s) {|f| yield Pathname.new(f) } と同じです。


//emlist[例][ruby]{
require "pathname"

P
athname("/usr/local").each_entry {|f| p f }

# => #<Pathname:.>
# => #<Pathname:..>
# => #<Pathname:bin>
# => #<Pathname:etc>
# => #<Pathname:include>
# => #<Pathname:lib>
# => #<Pathname:opt>
//}

@se...
...) {|f| yield Pathname.new(f) } と同じです。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
require "pathname"

P
athname("/usr/local").each_entry {|f| p f }

# => #<Pathname:.>
# => #<Pathname:..>
# => #<Pathname:bin>
# => #<Pathname:etc>
# => #<Pathna...
...me:include>
# => #<Pathname:lib>
# => #<Pathname:opt>
//}

@see Dir.foreach...

Pathname#find {|pathname| ...} -> nil (3107.0)

self 配下のすべてのファイルやディレクトリを 一つずつ引数 pathname に渡してブロックを実行します。

...self 配下のすべてのファイルやディレクトリを
一つずつ引数 pathname に渡してブロックを実行します。

require 'find'
Find.find(self.to_s) {|f| yield Pathname.new(f)}

と同じです。

ブロックを省略した場合は Enumerator を返します。


@see...

Pathname#find(ignore_error: true) {|pathname| ...} -> nil (3107.0)

self 配下のすべてのファイルやディレクトリを 一つずつ引数 pathname に渡してブロックを実行します。

...ディレクトリを
一つずつ引数 pathname に渡してブロックを実行します。

require 'find'
Find.find(self.to_s) {|f| yield Pathname.new(f)}

と同じです。

ブロックを省略した場合は Enumerator を返します。

@param ignore_error 探索中に発生した...

絞り込み条件を変える

StopIteration#result -> object (3055.0)

この例外オブジェクトを発生させる原因となったメソッド等の返り値を返します。

...object = Object.new
def object.each
yield
:yield1
yield
:yield2
:each_returned
end

enumerator = object.to_enum

p
enumerator.next #=> :yield1
p
enumerator.next #=> :yield2

begin
enumerator.next
rescue StopIteration => error
p
error.result #=> :each_returned
en...

Exception#==(other) -> bool (3031.0)

自身と指定された other のクラスが同じであり、 message と backtrace が == メソッドで比較して 等しい場合に true を返します。そうでない場合に false を返します。

...。そうでない場合に false を返します。

@param other 自身と比較したいオブジェクトを指定します。
自身と異なるクラスのオブジェクトを指定した場合は
Exception#exception を実行して変換を試みます。

//emlist[...
...} is not long month"
end

def get_exception
return begin
yield

rescue => e
e
end
end

results = [2, 2, 4].map { |e | get_exception { check_long_month(e) } }
p
results.map { |e| e.class }
# => [RuntimeError, RuntimeError, RuntimeError]
p
results.map { |e| e.message }
# => ["2 is not lon...
...g month", "2 is not long month", "4 is not long month"]

# class, message, backtrace が同一のため true になる
p
results[0] == results[1] # => true

# class, backtrace が同一だが、message がことなるため false になる
p
results[0] == results[2] # => false
//}...
<< 1 2 3 ... > >>