るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

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

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

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

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

d:spec/literal#command も参照。

@param command コマンドとして実行する引数です。そ...
...Errno::EXXX コマンドを実行できないときや失敗した場合に発生します。

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

@see Kernel.#system,Kernel.#exec,Kernel.#spawn...

Process::Status (8054.0)

プロセスの終了ステータスを表すクラスです。 メソッド Process.#wait2 などの返り値として使われます。

...exited normally. status=#{$?.exitstatus}"
else
p "unknown status %#x" % $?.to_i
end

SIGCHLD を trap する例

trap(:SIGCHLD) {|sig|

puts
"interrupted by signal #{sig} at #{caller[1]}"
# 複数の子プロセスの終了に対して1つの SIGCHLD しか届かない
# 場...
...signaled?
puts
" child #{$?.pid} was killed by signal #{$?.termsig}"
if $?.coredump?
puts
" child #{$?.pid} dumped core."
end
when $?.stopped?
puts
" child #{$?.pid} was stopped by signal #{$?.stopsig}"
when $?.exited?
puts
" chil...
...Errno::ECHILD
puts
"done"
end

=> 12964
12965
interrupted by signal 17 at -:27:in `sleep'
child 12965 was stopped by signal 19
interrupted by signal 17 at -:30:in `sleep'
child 12965 was killed by signal 15
interrupted by signal 17 at -:30:in `sleep'...

Thread::Backtrace::Location (8042.0)

Ruby のフレームを表すクラスです。

...p)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end

c(0..2).map do |call|
puts
call.to_s
end
//}

例1の実行結果:

caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'

//emlist[例2][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def in...
...kip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
puts
call.to_s
end
//}

例2の実行結果:

init.rb:4:in `initialize'
init.rb:8:in `new'
init.rb:8:in `<main>'

=== 参考

* Ruby VM アドベントカレンダー #4 vm_backtrace.c: https://www...

NoMethodError (8030.0)

定義されていないメソッドの呼び出しが行われたときに発生します。

...:

self.bar
# => -:1: undefined method `bar' for #<Object:0x401a6c40> (NoMethodError)

プライベートなインスタンスメソッドを呼び出そうとした場合にも発生します。

例:

"".puts
# => NoMethodError: private method `puts' called for "":String

メソッド呼...
...び出しの形式でなければ NameError 例外が発生します。

例:

bar
# => -:1: undefined local variable or method `bar' for #<Object:0x401a6c40> (NameError)...

Kernel.#exec(command, options={}) -> () (8018.0)

引数で指定されたコマンドを実行します。

...ドからは戻りません。

=== 引数の解釈

この形式では command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。

@param comma...
...:EXXX 起動に失敗し、ruby インタプリタに制御が戻った場合に発生します。

//emlist[例][ruby]{
# a.rb
puts
'実行前'
exec 'echo "実行中"'
puts
'実行後'
//}

上記のスクリプトを実行すると以下のようになります。

$ ruby a.rb
実行前
...

絞り込み条件を変える

Kernel.#exec(env, command, options={}) -> () (8018.0)

引数で指定されたコマンドを実行します。

...ドからは戻りません。

=== 引数の解釈

この形式では command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。

@param comma...
...:EXXX 起動に失敗し、ruby インタプリタに制御が戻った場合に発生します。

//emlist[例][ruby]{
# a.rb
puts
'実行前'
exec 'echo "実行中"'
puts
'実行後'
//}

上記のスクリプトを実行すると以下のようになります。

$ ruby a.rb
実行前
...

Thread::Backtrace::Location#inspect -> String (8018.0)

Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。

...][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
puts
call.inspect
end

# => "path/to/foo.rb:5:in `initialize'"
# "path/to/foo.rb:9:in `new'"
# "path/to/foo.rb:9:in `<main>'"
//}...

Thread::Backtrace::Location#to_s -> String (8018.0)

self が表すフレームを Kernel.#caller と同じ表現にした文字列を返し ます。

...mlist[例][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
puts
call.to_s
end

# => path/to/foo.rb:5:in `initialize'
# path/to/foo.rb:9:in `new'
# path/to/foo.rb:9:in `<main>'
//}...

Regexp#match(str, pos = 0) -> MatchData | nil (8012.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...pos から行うよう制御できます(pos のデフォルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if reg.match("foobar")
puts
"match"
end
# => match

p reg.match("foobar") # => #<MatchData:0x29403fc>
p reg.match("bar") # => nil

p /(foo)(bar)(baz)/.match("foobarbaz").t...
...に * を付けることで to_a の結果を利用でき
ます。つまり、上記は以下のように書くことができます。(ここでの
`
_' は、$& を捨てるために適当に選んだ変数名)

//emlist[例][ruby]{
_, foo, bar, baz = */(foo)(bar)(baz)/.match("foobarbaz")
p [foo,...
...s では、マッチに失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。

//emlist[例][ruby]{
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures

# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)
//}...
...に失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。

//emlist[例][ruby]{
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures

# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)
//}

@see Regexp#match?...

Regexp#match(str, pos = 0) {|m| ... } -> object | nil (8012.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...pos から行うよう制御できます(pos のデフォルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if reg.match("foobar")
puts
"match"
end
# => match

p reg.match("foobar") # => #<MatchData:0x29403fc>
p reg.match("bar") # => nil

p /(foo)(bar)(baz)/.match("foobarbaz").t...
...に * を付けることで to_a の結果を利用でき
ます。つまり、上記は以下のように書くことができます。(ここでの
`
_' は、$& を捨てるために適当に選んだ変数名)

//emlist[例][ruby]{
_, foo, bar, baz = */(foo)(bar)(baz)/.match("foobarbaz")
p [foo,...
...に失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。

//emlist[例][ruby]{
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures

# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)
//}

@see Regexp#match?...

絞り込み条件を変える

<< 1 2 > >>