This article was migrated from http://rai
Rubyのnewメソッドとallocateメソッドの挙動に関するメモ。
$ irb >> class Foo >> def initialize(a) >> @foo = a >> end >> def foo >> initialize ("test") >> end >> end => nil >> a = Foo.new("bb") => #<Foo:0x4020 3ce0 @foo="bb"> >> b = Foo.alloca te => #<Foo:0x401f 4b50> >> b.foo => "test" >> b => #<Foo:0x401f 4b50 @foo="test">
new*1 = allocate + initialize *2
ということですね。ファクトリーパターンを実装するのが楽になりそう。
This article was migrated from http://rai
posted by
genki
on Fri 29 Dec 2006
at 14:40