別のキーワード
種類
- インスタンスメソッド (15)
- 特異メソッド (3)
- 文書 (2)
- モジュール関数 (2)
クラス
- Enumerator (1)
-
Enumerator
:: Lazy (5) -
Enumerator
:: Yielder (3) - Exception (1)
- Fiber (1)
-
Net
:: POP3 (1) - Object (2)
- Pathname (1)
- Proc (1)
- Thread (2)
モジュール
- Kernel (2)
キーワード
- << (1)
- Ruby プログラムの実行 (1)
- [] (1)
-
backtrace
_ locations (1) -
enum
_ for (2) - feed (1)
- find (1)
- foreach (1)
- lambda (1)
- new (1)
- proc (1)
-
thread
_ variable _ get (1) -
to
_ enum (2) -
to
_ proc (1) -
yield
_ self (2) - 制御構造 (1)
検索結果
先頭5件
-
Enumerator
:: Yielder # yield(*object) -> () (109258.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
# => [... -
Fiber
. yield(*arg = nil) -> object (91240.0) -
現在のファイバーの親にコンテキストを切り替えます。
現在のファイバーの親にコンテキストを切り替えます。
コンテキストの切り替えの際に Fiber#resume に与えられた引数を yield メソッドは返します。
@param arg 現在のファイバーの親に渡したいオブジェクトを指定します。
@raise FiberError Fiber でのルートファイバーで呼ばれた場合に発生します。
//emlist[例:][ruby]{
a = nil
f = Fiber.new do
a = Fiber.yield()
end
f.resume()
f.resume(:foo)
p a #=> :foo
//} -
Proc
# yield(*arg) -> () (64222.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 sign(7) #=> 1... -
Kernel
. # lambda { . . . } -> Proc (36937.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があります。
& 引数を渡した lambda は Warning[:deprecated] = true のときに警告メッセージ
「warning: lambda without a literal block is deprecated; use the proc without lambda instead」
を出力します。
@raise Argum... -
Thread
# thread _ variable _ get(key) -> object | nil (36919.0) -
引数 key で指定した名前のスレッドローカル変数を返します。
引数 key で指定した名前のスレッドローカル変数を返します。
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。
例:
Thread.new {
Thread.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["foo"] = "bar" # Fiber ローカル
Fiber.new {
Fiber.yield ... -
Object
# yield _ self -> Enumerator (28297.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
... -
Object
# yield _ self {|x| . . . } -> object (28297.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
... -
Enumerator
:: Yielder # to _ proc -> Proc (27319.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"
# "こんにちは... -
Enumerator
:: Yielder # <<(object) -> () (27301.0) -
Enumerator.new で使うメソッドです。
Enumerator.new で使うメソッドです。
生成された Enumerator オブジェクトの each メソッドを呼ぶと
Enumerator::Yielder オブジェクトが渡されたブロックが実行され、
ブロック内の << が呼ばれるたびに each に渡されたブロックが
<< に渡された値とともに繰り返されます。
//emlist[例][ruby]{
enum = Enumerator.new do |y|
y << 1
y << 2
y << 3
end
enum.each do |v|
p v
end
# => 1
# 2
# 3
//} -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (19219.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
バックトレース情報を返します。Exception#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。
//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if Date.new(2000, month, -1).day == 31
raise "#{month} is not long month"
end
... -
Enumerator
# feed(obj) -> nil (19057.0) -
Enumerator 内部の yield が返す値を設定します。
Enumerator 内部の yield が返す値を設定します。
これで値を設定しなかった場合は yield は nil を返します。
この値は内部で yield された時点でクリアされます。
//emlist[例][ruby]{
# (1), (2), ... (10) の順に実行される
o = Object.new
def o.each
x = yield # (2) blocks
p x # (5) => "foo"
x = yield # (6) blocks
p x # (... -
Pathname
# find(ignore _ error: true) {|pathname| . . . } -> nil (18919.0) -
self 配下のすべてのファイルやディレクトリを 一つずつ引数 pathname に渡してブロックを実行します。
self 配下のすべてのファイルやディレクトリを
一つずつ引数 pathname に渡してブロックを実行します。
require 'find'
Find.find(self.to_s) {|f| yield Pathname.new(f)}
と同じです。
ブロックを省略した場合は Enumerator を返します。
@param ignore_error 探索中に発生した例外を無視するかどうかを指定します。
@see Find.#find -
Kernel
. # proc { . . . } -> Proc (18337.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があります。
& 引数を渡した lambda は Warning[:deprecated] = true のときに警告メッセージ
「warning: lambda without a literal block is deprecated; use the proc without lambda instead」
を出力します。
@raise Argum... -
Enumerator
:: Lazy . new(obj , size=nil) {|yielder , *values| . . . } -> Enumerator :: Lazy (10267.0) -
Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を 指定できます。
Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに
よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ
ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を
指定できます。
//emlist[Enumerable#filter_map と、その遅延評価版を定義する例][ruby]{
module Enumerable
def filter_map(&block)
map(&block).compact
end
end
class Enumerator::... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) -> Enumerator :: Lazy (9919.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) ... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (9919.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) ... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) -> Enumerator :: Lazy (9919.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) ... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (9919.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) ... -
Thread
# [](name) -> object | nil (9637.0) -
name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。
name に対応したスレッドに固有のデータを取り出します。
name に対応するスレッド固有データがなければ nil を返し
ます。
@param name スレッド固有データのキーを文字列か Symbol で指定します。
//emlist[例][ruby]{
[
Thread.new { Thread.current["name"] = "A" },
Thread.new { Thread.current[:name] = "B" },
Thread.new { Thread.current["name"] = "C" }
].each do |th|
th.join... -
制御構造 (9361.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
制御構造
条件分岐:
* if
* unless
* case
繰り返し:
* while
* until
* for
* break
* next
* redo
* retry
例外処理:
* raise
* begin
その他:
* return
* BEGIN
* END
Rubyでは(Cなどとは異なり)制御構造は式であって、何らかの値を返すものが
あります(返さないものもあります。値を返さない式を代入式の右辺に置くと
syntax error になります)。
R... -
Ruby プログラムの実行 (9109.0)
-
Ruby プログラムの実行 === Ruby プログラム
Ruby プログラムの実行
=== Ruby プログラム
Ruby プログラムの実行は文の連なりの評価です。なんらかの形であたえられたプログラムテキストをコンパイルし、BEGIN 文があればそれを評価し、トップレベルの式の連なりを評価し、END ブロックがあれば最後にそれを評価して終了します (終了処理の詳細については spec/terminate を参照のこと)。
=== 文
==== if
if 文は、まず条件式を評価し、その値が真ならば対応する本体を評価します。
偽ならば elsif 節の条件式を順番に評価し、その値が始めて真になった節の
本体を評価します。それらがすべて偽なら... -
Net
:: POP3 . foreach(address , port = nil , account , password , isapop=false) {|mail| . . . . } -> () (919.0) -
POP セッションを開始し、 サーバ上のすべてのメールを取りだし、 個々のメールを引数としてブロックを呼びだします。
POP セッションを開始し、
サーバ上のすべてのメールを取りだし、
個々のメールを引数としてブロックを呼びだします。
個々のメールは Net::POPMail のインスタンスで渡されます。
port に nil を渡すと、適当なポート(通常は110、SSL利用時には 995)を
使います。
以下のコードと同様の処理をします。
require 'net/pop'
Net::POP3.start(address, port, account, password, isapop=false) {|pop|
pop.each_mail do |m|
yield m
...