るりまサーチ

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

別のキーワード

  1. singleton clone
  2. singleton instance
  3. object define_singleton_method
  4. _builtin define_singleton_method

ライブラリ

検索結果

Object#initialize_copy(obj) -> object (61.0)

(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。

...self を obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object
#clone, Object#dupの内部で使われています。

initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに使...
...、そういった内部情
報を initialize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。

デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメ...
...j = Object.new
class <<obj
attr_accessor :foo
def bar
:bar
end
end

def check(obj)
puts "instance variables: #{obj.inspect}"
puts "tainted?: #{obj.tainted?}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end
end

obj.foo = 1
obj.taint

check Object.n...
...//emlist[][ruby]{
obj = Object.new
class <<obj
attr_accessor :foo
def bar
:bar
end
end

def check(obj)
puts "instance variables: #{obj.inspect}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end
end

obj.foo = 1

check Object.new.send(:initialize_cop...