るりまサーチ

最速Rubyリファレンスマニュアル検索!
376件ヒット [1-100件を表示] (0.171秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

種類

キーワード

検索結果

<< 1 2 3 ... > >>

Kernel.#`(command) -> String (29159.0)

command を外部コマンドとして実行し、その標準出力を文字列として 返します。このメソッドは `command` の形式で呼ばれます。

...command を外部コマンドとして実行し、その標準出力を文字列として
返します。このメソッドは `command` の形式で呼ばれます。

引数 command に対しダブルクォートで囲まれた文字列と同様の解釈と式展開を行った後、
コマンド...
...力を得る必要がなく、単にコマンドを実行したいだけなら
Kernel
.#system を使います。特に端末を制御するコマンドでは
`
command` は失敗するかもしれません。

d:spec/literal#command も参照。

@param command コマンドとして実行する引数...
...す。
@return コマンドの出力を文字列で返します。
@raise Errno::EXXX コマンドを実行できないときや失敗した場合に発生します。

//emlist[例][ruby]{
puts `ruby -v` #=> ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
puts $?.inspect #=> #<Process::Status:...

Kernel.#Integer(arg, base = 0) -> Integer (17221.0)

引数を整数 (Fixnum,Bignum) に変換した結果を返します。

...に対しては arg.to_int, arg.to_i を
この順に使用して変換します。

@param arg 変換対象のオブジェクトです。

@param base 基数として0か2から36の整数を指定します(引数argに文字列を指
定した場合のみ)。省略するか0を指定...
...数) です。


@raise ArgumentError 整数と見なせない文字列を引数に指定した場合に発生します。
@raise TypeError メソッド to_int, to_i を持たないオブジェクトを引数に指定したか、to_int, to_i
が整数(Integerのサブクラス)を返さ...
...@raise TypeError 引数に nil を指定した場合に発生します。

//emlist[例][ruby]{
p Integer(4) #=> 4
p Integer(4_000) #=> 4000
p Integer(9.88) #=> 9

p Integer(nil) # can't convert nil into Integer (TypeError)
p Integer(Object.new) # cannot convert Object in...

Kernel.#Integer(arg, base = 0, exception: true) -> Integer | nil (17221.0)

引数を整数 (Fixnum,Bignum) に変換した結果を返します。

...に対しては arg.to_int, arg.to_i を
この順に使用して変換します。

@param arg 変換対象のオブジェクトです。

@param base 基数として0か2から36の整数を指定します(引数argに文字列を指
定した場合のみ)。省略するか0を指定...
...です。

@param exception false を指定すると、変換できなかった場合、
例外を発生する代わりに nil を返します。

@raise ArgumentError 整数と見なせない文字列を引数に指定した場合に発生します。
@raise TypeError メソッド...
...(Integerのサブクラス)を返さなかった場合に発生します。
@raise TypeError 引数に nil を指定した場合に発生します。

//emlist[例][ruby]{
p Integer(4) #=> 4
p Integer(4_000) #=> 4000
p Integer(9.88) #=> 9

p Integer(nil) # can't convert ni...

Kernel.#caller_locations(range) -> [Thread::Backtrace::Location] | nil (17133.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...ムを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@param range 取得...
...Range オブジェクトを指定します。

//emlist[例][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
e
nd

def test2(start, length)
test1(start, length)
e
nd

def test3(start, length)
test2(s...
...t, length)
e
nd

caller_locations # => []
test3(1, nil)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test3(1, 2)
# => ["/Users/user/test....

Kernel.#caller_locations(start = 1, length = nil) -> [Thread::Backtrace::Location] | nil (17133.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...ムを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@param range 取得...
...Range オブジェクトを指定します。

//emlist[例][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
e
nd

def test2(start, length)
test1(start, length)
e
nd

def test3(start, length)
test2(s...
...t, length)
e
nd

caller_locations # => []
test3(1, nil)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test3(1, 2)
# => ["/Users/user/test....

絞り込み条件を変える

Kernel.#caller(range) -> [String] | nil (17121.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...す。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。

引数で指定した値が範囲外の場合は nil を返します。

@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得す...
...m range 取得したいスタックの範囲を示す 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)
e
nd

def bar
foo
e
nd

ba...
...:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []
# nil
//}

以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。

//emlist[例][ruby]{
def parse_caller(a...

Kernel.#caller(start = 1) -> [String] | nil (17121.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...す。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。

引数で指定した値が範囲外の場合は nil を返します。

@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得す...
...m range 取得したいスタックの範囲を示す 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)
e
nd

def bar
foo
e
nd

ba...
...:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []
# nil
//}

以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。

//emlist[例][ruby]{
def parse_caller(a...

Kernel.#caller(start, length) -> [String] | nil (17121.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...す。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。

引数で指定した値が範囲外の場合は nil を返します。

@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得す...
...m range 取得したいスタックの範囲を示す 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)
e
nd

def bar
foo
e
nd

ba...
...:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []
# nil
//}

以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。

//emlist[例][ruby]{
def parse_caller(a...

Kernel$$` -> String | nil (17103.0)

現在のスコープで最後に成功した正規表現のパターンマッチでマッチした 部分より前の文字列です。 最後のマッチが失敗していた場合には nil となります。

...

Regexp.last_match.pre_match と同じです。

この変数はローカルスコープかつスレッドローカル、読み取り専用です。
Ruby起動時の初期値は nil です。

//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">...
...(.*?)</a>] =~ str
p $`
e
nd
#=> "<p>"
//}...

Kernel.#system(command, options={}) -> bool | nil (14127.0)

引数を外部コマンドとして実行して、成功した時に真を返します。

...ると成功とみなし true を返します。
それ以外の終了ステータスの場合は false を返します。
コマンドを実行できなかった場合は nil を返します。

options で :exception に true を指定することで、
nil や false を返す代わりに例外を...
...mand が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。

@param command command コマンドを文字列で指定します。
@param env 更新...
...ータ Hash
@raise Errno::EXXX exception: true が指定されていて、コマンドの実行が失敗したときに発生します。
@raise RuntimeError exception: true が指定されていて、コマンドの終了ステータスが 0 以外のときに発生します。

//emlist[シェル...

絞り込み条件を変える

Kernel.#system(env, command, options={}) -> bool | nil (14127.0)

引数を外部コマンドとして実行して、成功した時に真を返します。

...ると成功とみなし true を返します。
それ以外の終了ステータスの場合は false を返します。
コマンドを実行できなかった場合は nil を返します。

options で :exception に true を指定することで、
nil や false を返す代わりに例外を...
...mand が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。

@param command command コマンドを文字列で指定します。
@param env 更新...
...ータ Hash
@raise Errno::EXXX exception: true が指定されていて、コマンドの実行が失敗したときに発生します。
@raise RuntimeError exception: true が指定されていて、コマンドの終了ステータスが 0 以外のときに発生します。

//emlist[シェル...
<< 1 2 3 ... > >>