るりまサーチ

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

別のキーワード

  1. fileutils remove_dir
  2. fileutils remove_entry
  3. fileutils remove_file
  4. fileutils remove
  5. rexml/document remove

ライブラリ

クラス

検索結果

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

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

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

@
param name String または Symbol を指定します。

@
return 引数で指定された定数に設定されていた値を返します。

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

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

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

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

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

Marshal フォーマット (66.0)

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

...lass Foo < Array # (or String, Regexp, Hash)
def initialize(obj)
@
foo = false
super(obj)
end
end
p Marshal.dump(Foo.new([true])).unpack("x2 a a a c a3 aca caca4 a")
# => ["I", "C", ":", 8, "Foo", "[", 6, "T", 6, ":", 9, "@foo", "F"]
//}

==== その他

実装上内部構造が異なる...
...タンス変数あり][ruby]{
class Foo
def initialize
@
foo = :bar
@
one = 1
end
end
p Marshal.dump(Foo.new).unpack("x2 a a c a3 c aca4 aca3 aca4 ac")
# => ["o", ":", 8, "Foo", 7,
# ":", 9, "@foo", ":", 8, "bar",
# ":", 9, "@one", "i", 6]
//}

=== Float

'f' で始まるデータ...
...le Bar
@
bar = 1
end
p Bar.instance_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 }...

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

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

...を返します。

@
param name 削除するインスタンス変数の名前をシンボルか文字列で指定します。
@
raise NameError オブジェクトがインスタンス変数 name を持たない場合に発生します。

//emlist[][ruby]{
class Foo
def foo
@
foo = 1
p remov...
...e_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...

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

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

...、そのクラス変数に設定さ
れていた値を返します。

@
param name String または Symbol を指定します。

@
return 引数で指定されたクラス変数に設定されていた値を返します。

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

//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...