るりまサーチ

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

別のキーワード

  1. etc sc_xopen_enh_i18n
  2. rsa n=
  3. rsa n
  4. pop n_bytes
  5. pop n_mails

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

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

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

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

生成された Enumerator オブジェクトの 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]
//}...

Exception#backtrace_locations -> [Thread::Backtrace::Location] (18507.0)

バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。

...on#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。

現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。

//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if Date.n...
...0, month, -1).day == 31
raise "#{month} is not long month"
end

def get_exception
return begin
yield

rescue => e
e
end
end

e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get...
..._exception'", "test.rb:15:in `<main>'"]
//}

@see Exception#backtrace...

Proc#yield(*arg) -> () (15262.0)

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

...#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...
...ような 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...

Enumerator::Lazy#enum_for(method = :each, *args) -> Enumerator::Lazy (12361.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (12361.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

絞り込み条件を変える

Enumerator::Lazy#to_enum(method = :each, *args) -> Enumerator::Lazy (12361.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

Enumerator::Lazy#to_enum(method = :each, *args) {|*args| block} -> Enumerator::Lazy (12361.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

Enumerator#next_values -> Array (12279.0)

「次」のオブジェクトを配列で返します。

...クトを配列で返します。

Enumerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。

このメソッドは、
yield


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

n
ext メソッドによる外部列挙...
...each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

//emlist[例: next と next_values の違いを][ruby]{
o = Object.new
def o.each
yield

yield
1
yield
1, 2
yield
nil
yield
[1, 2]
end
e = o.to_enum
p e.next_val...
...e.next_values
p e.next_values
p e.next_values
p e.next_values
e = o.to_enum
p e.next
p e.next
p e.next
p e.next
p e.next

## yield args next_values next
# yield [] nil
# yield 1 [1] 1
# yield 1, 2 [1, 2] [1, 2]
# yield nil...

Pathname#each_entry -> Enumerator (12217.0)

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

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

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

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

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

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

@see Dir.foreach...

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

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

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


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

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

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

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

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

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

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

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

@see Dir.foreach...

絞り込み条件を変える

<< 1 2 3 ... > >>