るりまサーチ

最速Rubyリファレンスマニュアル検索!
353件ヒット [101-200件を表示] (0.144秒)

別のキーワード

  1. matrix l
  2. kernel $-l
  3. _builtin $-l
  4. lupdecomposition l
  5. l

ライブラリ

クラス

モジュール

キーワード

検索結果

<< < 1 2 3 4 > >>

Thread#thread_variable_get(key) -> object | nil (6107.0)

引数 key で指定した名前のスレッドローカル変数を返します。

...:

Thread.new {
Thread.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["foo"] = "bar" # Fiber ローカル

Fiber.new {
Fiber.yield [
Thread.current.thread_variable_get("foo"), # スレッドローカル
Threa...
...}.resume
}.join.value # => ['bar', nil]

この例の "bar" は Thread#thread_variable_get により得られ
た値で、nil はThread#[] により得られた値です。

@see Thread#thread_variable_set, Thread#[]

@see https://magazine.rubyist.net/articles/0041/0041-200Special-note.html...

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

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

...tor::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"
//}...

Enumerator::Yielder#<<(object) -> () (6001.0)

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

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

//emlist[例][ruby]{
enum = Enumerator.new do...

Enumerable#each_entry {|obj| block} -> self (3113.0)

ブロックを各要素に一度ずつ適用します。

...配列として渡されます。

//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield
1
yield
1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}

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

@see Enumerable#slice_before...

Enumerable#max_by {|item| ... } -> object | nil (3107.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...しなければ nil を返します。
引数を指定する形式では、空の配列を返します。
該当する要素が複数存在する場合、どの要素を返すかは不定です。

Enumerable#max と Enumerable#max_by の
違いは Enumerable#sort と Enumerable#sort_by の違いと...
...

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}

//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "...
...x.length } # => ["albatross", "horse"]
//}

//emlist[例: enum.max_by(n)は、重み付きランダムサンプリングを実装するために使用できます。次の実装例は、Enumerable#wsampleを使用します。][ruby]{
module Enumerable
# weighted random sampling.
#
# Pavlos...

絞り込み条件を変える

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

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

...tor::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#t...
...: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 block_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 のおかげで、repeat の返り値は
# もとが Enumerator...

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

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

...tor::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#t...
...: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 block_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 のおかげで、repeat の返り値は
# もとが Enumerator...

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

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

...tor::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#t...
...: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 block_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 のおかげで、repeat の返り値は
# もとが Enumerator...

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

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

...tor::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#t...
...: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 block_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 のおかげで、repeat の返り値は
# もとが Enumerator...

Proc#call(*arg) -> () (3102.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) #=> -...
...ic 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を生成したメ...

絞り込み条件を変える

Enumerable#compact -> Array (3025.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...

Enumerable#each_entry -> Enumerator (3013.0)

ブロックを各要素に一度ずつ適用します。

...配列として渡されます。

//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield
1
yield
1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}

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

@see Enumerable#slice_before...
<< < 1 2 3 4 > >>