るりまサーチ

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

別のキーワード

  1. win32ole ole_activex_initialize
  2. object initialize_copy
  3. _builtin initialize_copy
  4. ri initialize
  5. _builtin initialize

ライブラリ

クラス

検索結果

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

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

...、Object#clone の内部で Object#initialize_clone から、
また Object#dup の内部で Object#initialize_dup から呼ばれます。

initialize_copy
は、Ruby インタプリタが知り得ない情報をコピーするた
めに使用(定義)されます。例えば C 言語でクラス...
...one
を再定義する必要がなくなります。

デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。

initialize_copy
という名前のメソッドは
自動的に private に設定されます。...
...: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.new.send(:initialize_copy, obj)
#=> instance variab...
...ccessor :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_copy, obj)
#=> instance variables: #<Object:0x4019c9...

クラス/メソッドの定義 (102.0)

クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined

...結果
として他の言語における「関数」のように使えます。

//emlist[例][ruby]{
def hello # 引数のないメソッド。
puts
"Hello, world!"
end

def foo(a, b) # 引数のあるメソッド。括弧を省いてdef foo a, bとも
a + 3 * b
end
//}

メソッド名...
...t[例][ruby]{
def foo(x, *xs)
puts
"#{x} : #{xs.inspect}" # Object#inspect は p のような詳細な内部表示
end
foo(1) #=> 1 : []
foo(1, 2) #=> 1 : [2]
foo(1, 2, 3) #=> 1 : [2, 3]

def bar(x, *) # 残りの引数を単に無視したいとき
puts
"#{x}"
end
bar(1) #=...
...lic、Module#private、
Module#protected を用いて変更できます。ただし Object#initialize という名前のメソッドと
Object#initialize_copy という名前のメソッド
は定義する場所に関係なく常に private になります。

//emlist[例][ruby]{
def foo...

ruby 1.8.3 feature (42.0)

ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))

...
禁止されるようになりました。

$ cat mthd_taint.rb
th = Thread.new{
$SAFE = 3
class Hoge
def foo
puts
"safe level: #{$SAFE}"
end
end
}
th.join
p $SAFE
Hoge.new.foo

$ ruby-1.8.2 mthd_taint.rb
0
"sa...
...((<ruby-talk:146776>)) ((<ruby-talk:146894>))
$ cat test_dlg.rb
foo = Object.new
foo2 = SimpleDelegator.new(foo)
def foo.bar
puts
"bar"
end
foo2.bar

$ ruby-1.8.2 -r delegate test_dlg.rb
test_dlg.rb:6: undefined method `bar' for #<Object:0x4021b0a0> (N...
...特異クラスは複製できなくなりました。((<ruby-talk:142749>))

$ ruby-1.8.3 -e 'class << "str"; self end.dup'
-e:1:in `initialize_copy': can't copy singleton class (TypeError)
from -e:1

=== 2005-05-15
: Pathname#unlink [lib] [compat]
ディレクトリへのシ...