るりまサーチ

最速Rubyリファレンスマニュアル検索!
55件ヒット [1-55件を表示] (0.035秒)
トップページ > クエリ:class[x] > クエリ:remove_const[x]

別のキーワード

  1. fileutils remove_dir
  2. fileutils remove_entry
  3. fileutils remove_file
  4. fileutils remove
  5. fileutils remove_entry_secure

検索結果

Module#remove_const(name) -> object (18119.0)

name で指定した定数を取り除き、その定数に設定されていた値を 返します。

...定された定数がそのモジュールやクラスに定義されていない場合に発生します。

//emlist[例][ruby]{
class
Foo
FOO = 1
p remove_const(:FOO) # => 1
p FOO # => uninitialized constant FOO at Foo (NameError)
end
//}

組み込みクラス/モジュールを設...
...指定した(まだロードしてない)定数を含めて削除する事ができます。

取り除かれた定数は参照できなくなりますが、消える訳ではないので注意して
使用してください。

@see Module#remove_class_variable, Object#remove_instance_variable...

Module#remove_class_variable(name) -> object (6125.0)

引数で指定したクラス変数を取り除き、そのクラス変数に設定さ れていた値を返します。

...ールやクラスに定義されていない場合に発生します。

//emlist[例][ruby]{
class
Foo
@@foo = 1
remove_class_variable(:@@foo) # => 1
p @@foo # => uninitialized class variable @@foo in Foo (NameError)
end
//}

@see Module#remove_const, Object#remove_instance_variable...

Marshal フォーマット (120.0)

Marshal フォーマット フォーマットバージョン 4.8 を元に記述しています。

...nce of the user class

==== String, Regexp, Array, Hash のサブクラス (インスタンス変数なし)

'C' で始まるデータ構造になります。

//emlist{
| 'C' | クラス名(Symbol)の dump | 親クラスのインスタンスの dump |
//}

//emlist[例 1][ruby]{
class
Foo < Array #...
...構造になります。
d:marshal_format#instance_variableも参照してください。

//emlist[例 2: インスタンス変数あり][ruby]{
class
Foo < Array # (or String, Regexp, Hash)
def initialize(obj)
@foo = false
super(obj)
end
end
p Marshal.dump(Foo.new([true])).unpack("x2 a...
...tance_eval { @bar } # => 1
File.open('testfile', 'wb') do |f|
Marshal.dump(Bar, f)
end

# 別プログラム相当にするため remove_const
Object.send :remove_const, :Bar

module Bar
end

p bar = Marshal.load(File.binread('testfile'))
p bar.instance_eval { @bar }
# => nil
//}

//emlist[例 3:...

Ruby プログラムの実行 (102.0)

Ruby プログラムの実行 === Ruby プログラム

...ます。

書式

class
ClassName [< スーパークラス式]

end

クラス定義式は評価されるとまずクラスを生成しようとします。スーパークラ
ス式が指定されていたらそれを評価し、その値を上位クラスとする Class
クラスのイ...
...は例外 TypeError が発生します。

クラスを得たら次にそれを定数「ClassName」に代入します。これによってク
ラス名が決定されます。このとき同名の定数に Class のインスタンスでない
ものが代入されている場合は例外 TypeError...
...。定数が所属するクラスは代入が行われたブ
ロックの class です。また非常に特殊な例外としてメソッド
Module#const_set によっても定義が可能です。さらに
Module#remove_const を使うことで定義の取り消しが可能です。

すでに定...

Object#remove_instance_variable(name) -> object (18.0)

オブジェクトからインスタンス変数 name を取り除き、そのインス タンス変数に設定されていた値を返します。

...ない場合に発生します。

//emlist[][ruby]{
class
Foo
def foo
@foo = 1
p remove_instance_variable(:@foo) #=> 1
p remove_instance_variable(:@foo) # instance variable @foo not defined (NameError)
end
end
Foo.new.foo
//}

@see Module#remove_class_variable,Module#remove_const...

絞り込み条件を変える