キーワード
-
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) -
ruby 1
. 6 feature (11) - クラス/メソッドの定義 (11)
- メソッド呼び出し(super・ブロック付き・yield) (11)
- 制御構造 (11)
検索結果
-
制御構造 (31.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...て、何らかの値を返すものが
あります(返さないものもあります。値を返さない式を代入式の右辺に置くと
syntax error になります)。
RubyはC言語やPerlから引き継いだ制御構造を持ちますが、
その他にd:spec/call#blockという
制御......場合には例外 SyntaxError が発生
します。
=== 例外処理
====[a:raise] raise
//emlist[例][ruby]{
raise "you lose" # 例外 RuntimeError を発生させる
# 以下の二つは SyntaxError を発生させる
raise SyntaxError, "invalid syntax"
raise SyntaxError.new("invalid syntax"......では書けません。全て SyntaxErrorになります。
def foo
BEGIN { p "begin" }
end
# => -e:2: syntax error, unexpected keyword_BEGIN
class Foo
BEGIN { p "begin" }
end
# => -e:2: syntax error, unexpected keyword_BEGIN... -
NEWS for Ruby 3
. 0 . 0 (19.0) -
NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...have been removed.
16131 17136
* yield in singleton class definitions in methods is now a SyntaxError
instead of a warning. yield in a class definition outside of a method
is now a SyntaxError instead of a LocalJumpError. 15575
* When a class variable is overtaken by the same defini......tionally, accessing a
class variable from the toplevel scope is now a RuntimeError.
14541
* Assigning to a numbered parameter is now a SyntaxError instead of
a warning.
== Command line options
=== `--help` option
When the environment variable `RUBY_PAGER` or `PAGER` is present and h... -
NEWS for Ruby 2
. 7 . 0 (7.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...の識別子の引用符は同じ行で閉じる必要があります。
//emlist{
<<"EOS
" # This had been warned since 2.4; Now it raises a SyntaxError
EOS
//}
* フリップフロップが非推奨になったのが元に戻されました。 5400
* 以下のような場所にコメント... -
ruby 1
. 6 feature (7.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...がありました。
((<ruby-list:34478>))
#! ruby -Ks
p a = "#{"表"}"
=> -:1: compile error in string expansion (SyntaxError)
-:1: unterminated string meets end of file
ruby 1.6.7 (2002-03-15) [i586-linux]
=> ruby 1.6.7 (2002-03-19) [i586-l... -
クラス/メソッドの定義 (7.0)
-
クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined
...[10, 20, 2, 3, 30]
p foo(10, 20, 30, 40) #=> [10, 20, 30, 3, 40]
p foo(10, 20, 30, 40, 50) #=> [10, 20, 30, 40, 50]
# NG: 次の定義は SyntaxError になる
# def foo(x = 1, y, z = 2)
# end
//}
デフォルト式の評価は呼び出し時にメソッド定義内のコンテキストで... -
メソッド呼び出し(super・ブロック付き・yield) (7.0)
-
メソッド呼び出し(super・ブロック付き・yield) * super * block * yield * block_arg * numbered_parameters * call_method
...に使うことはできません。
//emlist{
def foo
yield "a","b","c"
end
foo {|a, b, c| p [_1, a] } # => ordinary parameter is defined (SyntaxError)
//}
なお、ブロック内で _2 以降が使用されているかどうかで、_1 の意味が異なります。
//emlist[][ruby]{
def fo...