るりまサーチ

最速Rubyリファレンスマニュアル検索!
1053件ヒット [101-200件を表示] (0.070秒)

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

ライブラリ

モジュール

キーワード

検索結果

<< < 1 2 3 4 ... > >>

ObjectSpace.#define_finalizer(obj, proc) -> Array (19.0)

obj が解放されるときに実行されるファイナライザ proc を 登録します。同じオブジェクトについて複数回呼ばれたときは置き換えで はなく追加登録されます。固定値 0 と proc を配列にして返します。

...い例です。

//emlist[悪い例][ruby]{
class Foo
def initialize
ObjectSpace.define_finalizer(self) {
puts "foo"
}
end
end
Foo.new
GC.start
//}

これは、渡された proc の self が obj を参照しつ
づけるため。そのオブジェクトが GC の対象になりま...
...s Bar
def Bar.callback
proc {
puts "bar"
}
end
def initialize
ObjectSpace.define_finalizer(self, Bar.callback)
end
end
Bar.new
GC.start
//}

proc の呼び出しで発生した大域脱出(exitや例外)は無視されます。
これは、スクリプトのメイン処理...
...いでしょう。

//emlist[例][ruby]{
class Baz
def initialize
ObjectSpace.define_finalizer self, eval(%q{
proc {
raise "baz" rescue puts $!
raise "baz2"
puts "baz3"
}
}, TOPLEVEL_BINDING)
end
end
Baz.new
GC.start

# => baz
//}

@see spec/rubycmd...

ObjectSpace.#each_object -> Enumerator (19.0)

指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。

...ss_names"
# => "@corrections"
# => Total count: 9938
//}

//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")

count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"

# => #<struct Person name="sato"...

ObjectSpace.#each_object {|object| ...} -> Integer (19.0)

指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。

...ss_names"
# => "@corrections"
# => Total count: 9938
//}

//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")

count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"

# => #<struct Person name="sato"...

ObjectSpace.#each_object(klass) -> Enumerator (19.0)

指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。

...ss_names"
# => "@corrections"
# => Total count: 9938
//}

//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")

count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"

# => #<struct Person name="sato"...

ObjectSpace.#each_object(klass) {|object| ...} -> Integer (19.0)

指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。

...ss_names"
# => "@corrections"
# => Total count: 9938
//}

//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")

count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"

# => #<struct Person name="sato"...

絞り込み条件を変える

Kernel.#Complex(r, i = 0) -> Complex (13.0)

実部が r、虚部が i である Complex クラスのオブジェクトを生成します。

...ェクトを返しま
す。

//emlist[例][ruby]{
Complex('1+1i', '2+3i') # => (-2+3i)
Complex('1+1i') + Complex('2+3i') * Complex('i') # => (-2+3i)
//}

@see Complex.rect、Complex.rectangular

[注意] Complex.new、Complex.new! は 1.9 系では廃止されました。...

Kernel.#Complex(r, i = 0, exception: true) -> Complex | nil (13.0)

実部が r、虚部が i である Complex クラスのオブジェクトを生成します。

...ェクトを返しま
す。

//emlist[例][ruby]{
Complex('1+1i', '2+3i') # => (-2+3i)
Complex('1+1i') + Complex('2+3i') * Complex('i') # => (-2+3i)
//}

@see Complex.rect、Complex.rectangular

[注意] Complex.new、Complex.new! は 1.9 系では廃止されました。...

Kernel.#Complex(s) -> Complex (13.0)

実部が r、虚部が i である Complex クラスのオブジェクトを生成します。

...ェクトを返しま
す。

//emlist[例][ruby]{
Complex('1+1i', '2+3i') # => (-2+3i)
Complex('1+1i') + Complex('2+3i') * Complex('i') # => (-2+3i)
//}

@see Complex.rect、Complex.rectangular

[注意] Complex.new、Complex.new! は 1.9 系では廃止されました。...

Kernel.#Complex(s, exception: true) -> Complex | nil (13.0)

実部が r、虚部が i である Complex クラスのオブジェクトを生成します。

...ェクトを返しま
す。

//emlist[例][ruby]{
Complex('1+1i', '2+3i') # => (-2+3i)
Complex('1+1i') + Complex('2+3i') * Complex('i') # => (-2+3i)
//}

@see Complex.rect、Complex.rectangular

[注意] Complex.new、Complex.new! は 1.9 系では廃止されました。...

Kernel.#fail -> () (13.0)

例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。

...end

foo(4) #=> in method.in rescue.in method.in else.in ensure.
//}

//emlist[例3][ruby]{
class MyException
def exception(mesg=nil)
SecurityError.new(mesg)
end
end

begin
raise MyException.new
rescue SecurityError
p $! #=> #<SecurityError: SecurityError>
end
//}

@see Kernel.#caller...

絞り込み条件を変える

Kernel.#fail(error_type, message = nil, backtrace = caller(0), cause: $!) -> () (13.0)

例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。

...end

foo(4) #=> in method.in rescue.in method.in else.in ensure.
//}

//emlist[例3][ruby]{
class MyException
def exception(mesg=nil)
SecurityError.new(mesg)
end
end

begin
raise MyException.new
rescue SecurityError
p $! #=> #<SecurityError: SecurityError>
end
//}

@see Kernel.#caller...
<< < 1 2 3 4 ... > >>