ライブラリ
- ビルトイン (33)
モジュール
- Kernel (33)
キーワード
-
NEWS for Ruby 2
. 0 . 0 (11) - Ruby用語集 (11)
- クラス/メソッドの定義 (11)
- 制御構造 (11)
検索結果
先頭5件
-
Kernel
. # caller(range) -> [String] | nil (18217.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...情報を $@
の形式のバックトレース(文字列の配列)として返します。
トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を......caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(cal......oo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DE... -
Kernel
. # caller(start = 1) -> [String] | nil (18217.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...情報を $@
の形式のバックトレース(文字列の配列)として返します。
トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を......caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(cal......oo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DE... -
Kernel
. # caller(start , length) -> [String] | nil (18217.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...情報を $@
の形式のバックトレース(文字列の配列)として返します。
トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を......caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(cal......oo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DE... -
NEWS for Ruby 2
. 0 . 0 (1470.0) -
NEWS for Ruby 2.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...言語仕様の変更
* キーワード引数を追加しました
* %i, %I をシンボルの配列作成のために追加しました。(%w, %W に似ています)
* デフォルトのソースエンコーディングを US-ASCII から UTF-8 に変更しました
* '_' で始まる使......た
* 新規クラス: Enumerator::Lazy 遅延列挙用のクラス
* ENV
* ENV.to_h は ENV.to_hash へのエイリアスです
* Fiber
* 非互換: Fiber#resume は Fiber#transfer を呼び出したファイバーを再開できなくなりました
* File
* 拡張: File.f......s
* Kernel
* 追加: Kernel.#Hash という変換メソッド。Kernel.#Array, Kernel.#Float に似ています
* 追加: Kernel.#__dir__ 現在のソースファイル(__FILE__)のあるディレクトリ名を正規化された絶対パ スで返します。
* 追加: Kernel.#caller... -
クラス/メソッドの定義 (534.0)
-
クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined
...ソッドの定義
* クラス/メソッドの定義:
* class
* singleton_class
* module
* method
* operator
* nest_method
* eval_method
* singleton_method
* class_method
* limit
* 定義に関する操作:
* alias
* undef
* defined
===[a:c...... File::Constants を include することで、
# File::RDONLY などと書かずに直接 RDONLY と書くことができる。
class File
module Constants
RDONLY = 0
WRONLY = 1
end
include Constants
end
File.open("foo", File::RDONLY)
# あるいは
include File::Constants
File.ope......ん。
* protected に設定されたメソッドは、そのメソッドを持つオブジェクトが
selfであるコンテキスト(メソッド定義式やinstance_eval)でのみ呼び出せ
ます。
//emlist[例: protected の可視性][ruby]{
class Foo
def foo
p caller.last
en......す。
* protected に設定されたメソッドは、そのメソッドを持つオブジェクトが
selfであるコンテキスト(メソッド定義式やinstance_eval)でのみ呼び出せ
ます。
//emlist[例: protected の可視性][ruby]{
class Foo
def foo
p caller.last
en... -
制御構造 (306.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などとは異なり)制御構造は式であ......で指定された例外を、第二引数をメッセージとして発生さ
せます。第四の形式の第三引数は
$@または
Kernel.#callerで得られる
スタック情報で、例外が発生した場所を示します。
発生した例外は後述の begin 式の rescue 節で捕......ure 節を定義でき、これにより例外を処理することが
できます。
==== rescue修飾子
//emlist[例][ruby]{
open("nonexistent file") rescue STDERR.puts "Warning: #$!"
//}
文法:
式1 rescue 式2
式1で例外が発生したとき、式2を評価します。
以... -
Ruby用語集 (60.0)
-
Ruby用語集 A B C D E F G I J M N O R S Y
...m、標準添付ライブラリー
: Bundler
特定の Ruby アプリケーションで使用する gem とそのバージョンを Gemfile
および Gemfile.lock という
ファイルで管理するツール。gem を新規作成するときの雛形を生成する機能もある。
コ......str.size」「user&.name」といったメソッド呼び出しにおける
「.」「&.」も演算子である。
「[*0..9]」におけるいわゆる splat 展開の * や、
Proc オブジェクトをブロックとして渡す「strs.map(&:length)」に
おける & も演算子であ......おいて、そこに至るメソッド呼び出し元情報を遡るデータ。
バックトレースともいう。
Kernel.#caller_locations、Kernel.#caller で現時点までの
スタックトレースを得ることができる。
また、例外オブジェクトは例外が発生...