ライブラリ
- ビルトイン (204)
クラス
-
Encoding
:: InvalidByteSequenceError (24) - Exception (12)
- File (36)
- NoMethodError (12)
- Object (12)
- Regexp (24)
- SystemCallError (12)
モジュール
- Kernel (36)
- ObjectSpace (24)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - === (12)
- Thread (12)
- args (12)
- cause (12)
-
define
_ finalizer (24) - delete (12)
-
error
_ bytes (12) - fail (12)
-
incomplete
_ input? (12) -
initialize
_ copy (12) -
last
_ match (24) - raise (12)
- rename (12)
- unlink (12)
- スレッド (12)
- 制御構造 (12)
検索結果
先頭5件
-
Kernel
$ $ ! -> Exception | nil (18201.0) -
最後に例外が発生したときの Exception オブジェクトです。 該当する例外がないときは nil です。
...最後に例外が発生したときの Exception オブジェクトです。
該当する例外がないときは nil です。
Kernel.#raise によって設定されます。
この変数はスレッドローカル、読み取り専用です。... -
Encoding
:: InvalidByteSequenceError # incomplete _ input? -> bool (9112.0) -
エラー発生時に入力文字列が不足している場合に真を返します。
...//emlist[例][ruby]{
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
begin
ec.convert("abc\xA1z")
rescue Encoding::InvalidByteSequenceError
p $!
#=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "z" on EUC-JP>
p $!.incomplete_input? #=> false
end
begin
ec.convert("abc\......xA1")
ec.finish
rescue Encoding::InvalidByteSequenceError
p $! #=> #<Encoding::InvalidByteSequenceError: incomplete "\xA1" on EUC-JP>
p $!.incomplete_input? #=> true
end
//}... -
Encoding
:: InvalidByteSequenceError # error _ bytes -> String (9106.0) -
エラー発生時に捨てられたバイト列を返します。
...emlist[例][ruby]{
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
begin
ec.convert("abc\xA1\xFFdef")
rescue Encoding::InvalidByteSequenceError
p $!
#=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "\xFF" on EUC-JP>
puts $!.error_bytes.dump #=> "\xA1"
puts $!.read......again_bytes.dump #=> "\xFF"
end
//}
@see Encoding::InvalidByteSequenceError#readagain_bytes... -
File
. delete(*filename) -> Integer (6206.0) -
ファイルを削除します。削除したファイルの数を返します。 削除に失敗した場合は例外 Errno::EXXX が発生します。
...。
//emlist[例][ruby]{
IO.write("test.txt", "test")
p File.exist?("test.txt") # => true
p File.delete("test.txt") # => 1
p File.exist?("test.txt") # => false
begin
File.delete("test.txt")
rescue
p $! # => #<Errno::ENOENT: No such file or directory @ unlink_internal - test.txt>
end
//}... -
Object
# initialize _ copy(obj) -> object (6106.0) -
(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。
...数や特異メソッドは変化しません。
デフォルトでは、Object#clone の内部で Object#initialize_clone から、
また Object#dup の内部で Object#initialize_dup から呼ばれます。
initialize_copy は、Ruby インタプリタが知り得ない情報をコピーする......を initialize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。
デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。
initialize_......ist[][ruby]{
obj = Object.new
class <<obj
attr_accessor :foo
def bar
:bar
end
end
def check(obj)
puts "instance variables: #{obj.inspect}"
puts "tainted?: #{obj.tainted?}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end
end
obj.foo = 1
obj.taint......//emlist[][ruby]{
obj = Object.new
class <<obj
attr_accessor :foo
def bar
:bar
end
end
def check(obj)
puts "instance variables: #{obj.inspect}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end
end
obj.foo = 1
check Object.new.send(:initialize_cop... -
Regexp
. last _ match(nth) -> String | nil (6106.0) -
整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。
...整数 nth が 0 の場合、マッチした文字列を返します
($&)。それ以外では、nth 番目の括弧にマッチ
した部分文字列を返します($1,$2,...)。
対応する括弧がない場合やマッチしなかった場合には nil を返し
ます。
//emlist[例][ruby]{......ab"
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match(0) # => "ab"
p Regexp.last_match(1) # => "a"
p Regexp.last_match(2) # => "b"
p Regexp.last_match(3) # => nil
//}
正規表現全体がマッチしなかった場合、引数なしの
Regexp.last_match はnil を返......last_match[1] の形式では例外 NoMethodError が発生します。
対して、last_match(1) は nil を返します。
//emlist[例][ruby]{
str = "This is Regexp"
/That is Regexp/ =~ str
p Regexp.last_match # => nil
begin
p Regexp.last_match[1] # 例外が発生する
rescue
puts $! # =... -
Regexp
. last _ match -> MatchData (6101.0) -
カレントスコープで最後に行った正規表現マッチの MatchData オ ブジェクトを返します。このメソッドの呼び出しは $~ の参照と同じです。
...MatchData オ
ブジェクトを返します。このメソッドの呼び出しは $~
の参照と同じです。
//emlist[例][ruby]{
/(.)(.)/ =~ "ab"
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match[0] # => "ab"
p Regexp.last_match[1] # => "a"
p Regexp.last_match[2]......# => "b"
p Regexp.last_match[3] # => nil
//}... -
Thread (6018.0)
-
スレッドを表すクラスです。スレッドとはメモリ空間を共有して同時に実行される制御の流れです。 Thread を使うことで並行プログラミングが可能になります。
...同時に実行される制御の流れです。
Thread を使うことで並行プログラミングが可能になります。
=== 実装
ネイティブスレッドを用いて実装されていますが、
現在の実装では Ruby VM は Giant VM lock (GVL) を有しており、同時に実......ption] 例外発生時のスレッドの振る舞い
あるスレッドで例外が発生し、そのスレッド内で rescue で捕捉されなかっ
た場合、通常はそのスレッドだけがなにも警告なしに終了されます。ただ
しその例外で終了するスレッドを T......、同じ例外が再度
発生します。
begin
t = Thread.new do
Thread.pass # メインスレッドが確実にjoinするように
raise "unhandled exception"
end
t.join
rescue
p $! # => "unhandled exception"
end
また、以下の 3 つの方法により... -
Exception
# cause -> Exception | nil (3106.0) -
self の前の例外(self が rescue 節や ensure 節の中で発生した例外の場合、 その前に発生していた元々の例外)を返します。存在しない場合は nil を返し ます。
...その前に発生していた元々の例外)を返します。存在しない場合は nil を返し
ます。
//emlist[例][ruby]{
begin
begin
raise "inner"
rescue
raise "outer"
end
rescue
p $! # => #<RuntimeError: outer>
p $!.cause # => #<RuntimeError: inner>
end
//}...