M
Martin Boese
I'd like to define methods on initialize that are specific for the created
object. However it seems that the few lines of code below is defining them
somewhere else since they are 'overwriting' each other:
============
class Foo
def initialize(method_name, &block)
self.class.senddefine_method, method_name, &block)
end
end
aa = Foo.newwhoareyou) { puts "I am aa" }
bb = Foo.newwhoareyou) { puts "I am bb" }
aa.whoareyou
# returns: "I am bb" - But I expect: "I am aa"
bb.whoareyou
# returns: "I am bb"
Foo.whoareyou
# undefined method ===> Good
============
Thanks!
martin
object. However it seems that the few lines of code below is defining them
somewhere else since they are 'overwriting' each other:
============
class Foo
def initialize(method_name, &block)
self.class.senddefine_method, method_name, &block)
end
end
aa = Foo.newwhoareyou) { puts "I am aa" }
bb = Foo.newwhoareyou) { puts "I am bb" }
aa.whoareyou
# returns: "I am bb" - But I expect: "I am aa"
bb.whoareyou
# returns: "I am bb"
Foo.whoareyou
# undefined method ===> Good
============
Thanks!
martin