別のキーワード
検索結果
先頭5件
-
Kernel
. # String(arg) -> String (18243.0) -
引数を文字列(String)に変換した結果を返します。
...引数を文字列(String)に変換した結果を返します。
arg.to_s を呼び出して文字列に変換します。
arg が文字列の場合、何もせず arg を返します。
@param arg 変換対象のオブジェクトです。
@raise TypeError to_s の返り値が文字列でなけ......れば発生します。
//emlist[例][ruby]{
class Foo
def to_s
"hogehoge"
end
end
arg = Foo.new
p String(arg) #=> "hogehoge"
//}
@see Object#to_s,String... -
JSON
. # generate(object , state = nil) -> String (145.0) -
与えられたオブジェクトを一行の JSON 形式の文字列に変換して返します。
...文字列です。
: :space
a string that is put after, a : or , delimiter (default: '')
: :space_before
a string that is put before a : pair delimiter (default: '')
: :object_nl
a string that is put at the end of a JSON object (default: '')
: :array_nl
a string that is put at the end of a J......です。
@raise JSON::GeneratorError JSON::NaN, JSON::Infinity,JSON::MinusInfinity
を生成しようとした場合に発生します。
@raise JSON::CircularDatastructure 与えられたオブジェクトが循環参照を持つ場合に発生します。
//emlist[例][ruby]{
require "... -
JSON
. # unparse(object , state = nil) -> String (145.0) -
与えられたオブジェクトを一行の JSON 形式の文字列に変換して返します。
...文字列です。
: :space
a string that is put after, a : or , delimiter (default: '')
: :space_before
a string that is put before a : pair delimiter (default: '')
: :object_nl
a string that is put at the end of a JSON object (default: '')
: :array_nl
a string that is put at the end of a J......です。
@raise JSON::GeneratorError JSON::NaN, JSON::Infinity,JSON::MinusInfinity
を生成しようとした場合に発生します。
@raise JSON::CircularDatastructure 与えられたオブジェクトが循環参照を持つ場合に発生します。
//emlist[例][ruby]{
require "... -
Signal
. # trap(signal) { . . . } -> String | Proc | nil (139.0) -
指定された割り込み signal に対するハンドラとして command を登録します。 指定したシグナルが捕捉された時には例外が発生せず、代わりに command が実行されます。 ブロックを指定した場合にはブロックをハンドラとして登録します。
...していたらそれを Proc オブジェクトに変換して返します。
また何も登録されていないときも nil を返します。
ruby の仕組みの外でシグナルハンドラが登録された場合
(例えば拡張ライブラリが独自に sigaction を呼んだ場合な......指定できます。
これは「プログラムの終了時」を表します。
@param command シグナルハンドラとして Ruby プログラムを表す文字列か Proc オブジェクト、また次に挙げる文字列を
指定します。nil、空文字列......行ったあとステータス 0 で終了します。
文字列の代わりに Symbol で指定することも出来ます。
@raise ArgumentError 引数 signalに SEGV BUS ILL FPE VTALRM を指定した場
合に発生します。また、システムに定... -
Signal
. # trap(signal , command) -> String | Proc | nil (139.0) -
指定された割り込み signal に対するハンドラとして command を登録します。 指定したシグナルが捕捉された時には例外が発生せず、代わりに command が実行されます。 ブロックを指定した場合にはブロックをハンドラとして登録します。
...していたらそれを Proc オブジェクトに変換して返します。
また何も登録されていないときも nil を返します。
ruby の仕組みの外でシグナルハンドラが登録された場合
(例えば拡張ライブラリが独自に sigaction を呼んだ場合な......指定できます。
これは「プログラムの終了時」を表します。
@param command シグナルハンドラとして Ruby プログラムを表す文字列か Proc オブジェクト、また次に挙げる文字列を
指定します。nil、空文字列......行ったあとステータス 0 で終了します。
文字列の代わりに Symbol で指定することも出来ます。
@raise ArgumentError 引数 signalに SEGV BUS ILL FPE VTALRM を指定した場
合に発生します。また、システムに定... -
Marshal
. # dump(obj , limit = -1) -> String (132.0) -
obj を指定された出力先に再帰的に出力します。
...えば、デフォルト値を求めるブロックを持った Hash は
Proc を間接的に指していることになります。
//emlist[例][ruby]{
p Marshal.dump(Hash.new {})
# => -:1:in `dump': cannot dump hash with default proc (TypeError)
//}
マーシャルの動作を任意に定義す......obj をダンプした String を返します。
port を指定すると port を返します。
@raise TypeError ファイルに書き出せないオブジェクトをファイルに
書きだそうとした場合に発生します。
@raise ArgumentError 名前の......付いていない Class や Module
オブジェクトをダンプしようとした場合に発生します。
@raise ArgumentError limit 段以上深くリンクしたオブジェクトをダンプしようと
した場合に発生します。
@see Objec... -
Kernel
. # caller(range) -> [String] | nil (128.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...たいスタックの範囲を示す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `......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......=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}... -
Kernel
. # caller(start = 1) -> [String] | nil (128.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...たいスタックの範囲を示す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `......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......=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}... -
Kernel
. # caller(start , length) -> [String] | nil (128.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...たいスタックの範囲を示す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `......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......=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}...