22件ヒット
[1-22件を表示]
(0.049秒)
検索結果
-
Enumerator
# feed(obj) -> nil (18119.0) -
Enumerator 内部の yield が返す値を設定します。
...Object.new
def o.each
x = yield # (2) blocks
p x # (5) => "foo"
x = yield # (6) blocks
p x # (8) => nil
x = yield # (9) blocks
p x # not reached w/o another e.next
end
e = o.to_enum
e.next # (1)
e.feed "foo"......# (3)
e.next # (4)
e.next # (7)
# (10)
//}
@param obj Enumerator 内部の yield が返す値
@raise TypeError すでに値をこのメソッドでセットしている場合に発生します... -
制御構造 (118.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などとは異なり)制御構造は式であって、何らかの値を......結果を返します。
条件が成立しなければ nil を返します。
====[a:unless] unless
//emlist[例][ruby]{
unless baby?
feed_meat
else
feed_milk
end
//}
文法:
unless 式 [then]
式 ...
[else
式 ... ]
end
unless は if......:raise] raise
//emlist[例][ruby]{
raise "you lose" # 例外 RuntimeError を発生させる
# 以下の二つは SyntaxError を発生させる
raise SyntaxError, "invalid syntax"
raise SyntaxError.new("invalid syntax")
raise # 最後の例外の再発生
//}
文法:
raise...