ライブラリ
- ビルトイン (88)
クラス
- File (33)
- Regexp (22)
- SystemCallError (11)
- Thread (11)
- TracePoint (11)
キーワード
- === (11)
- delete (11)
-
handle
_ interrupt (11) -
last
_ match (22) - new (11)
- rename (11)
- unlink (11)
検索結果
先頭5件
-
File
. delete(*filename) -> Integer (8007.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
//}... -
File
. rename(from , to) -> 0 (8007.0) -
ファイルの名前を変更します。ディレクトリが異なる場合には移動も行い ます。rename(2) を参照してください。移動先のファ イルが存在する時には上書きされます。
...@param to 新しいファイル名を文字列で与えます。
@raise Errno::EXXX 失敗した場合に発生します。
//emlist[例][ruby]{
begin
File.rename("testfile", "testfile.bak") # => 0
File.rename("testfile", "testfile.bak")
rescue
# 2回目の rename 時にすでに testfile... -
File
. unlink(*filename) -> Integer (8007.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
//}... -
Regexp
. last _ match(nth) -> String | nil (8007.0) -
整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。
...して、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 $! # => undefined method `[]' for nil:NilClass
end
p Regexp.last_match(1) # => nil... -
SystemCallError
. ===(other) -> bool (8007.0) -
other が SystemCallError のサブクラスのインスタンスで、 かつ、other.errno の値が self::Errno と同じ場合に真を返します。そうでない場合は偽を返します。
...と同じ意味しかありません。
@param other 任意のオブジェクト
例
p Errno::EAGAIN::Errno
p Errno::EWOULDBLOCK::Errno
begin
raise Errno::EAGAIN, "pseudo error"
rescue Errno::EWOULDBLOCK
p $!
end
# => 11
11
#<Errno::EAGAIN: ps... -
Thread
. handle _ interrupt(hash) { . . . } -> object (8007.0) -
スレッドの割り込みのタイミングを引数で指定した内容に変更してブロックを 実行します。
...い方
例:Thread#raise 発生のタイミングを制御する例
th = Thread.new do
Thread.handle_interrupt(RuntimeError => :never) {
begin
# 安全にリソースの割り当てが可能
Thread.handle_interrupt(RuntimeError => :immediate) {
# ...
}... -
TracePoint
. new(*events) {|obj| . . . } -> TracePoint (8007.0) -
新しい TracePoint オブジェクトを作成して返します。トレースを有効 にするには TracePoint#enable を実行してください。
...からのリターン。
: :raise
例外の発生。
: :b_call
ブロックの開始。
: :b_return
ブロックの終了。
: :thread_begin
スレッドの開始。
: :thread_end
スレッドの終了。
指定イベントに関連しない情報を取得するメソッドを......からのリターン。
: :raise
例外の発生。
: :b_call
ブロックの開始。
: :b_return
ブロックの終了。
: :thread_begin
スレッドの開始。
: :thread_end
スレッドの終了。
: :fiber_switch
ファイバーの切り替え。
指定イベント......からのリターン。
: :raise
例外の発生。
: :b_call
ブロックの開始。
: :b_return
ブロックの終了。
: :thread_begin
スレッドの開始。
: :thread_end
スレッドの終了。
: :fiber_switch
ファイバーの切り替え。
: :script_compiled... -
Regexp
. last _ match -> MatchData (8002.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...