A
Andrea Fazzi
Hi all,
I'd like to re-open a class and to re-initialize its original constructor:
class Foo
def initialize
yield self if block_given?
end
end
class Foo
attr_reader :var
alias foo_initialize initialize
def initialize
foo_initialize
@var = "Foo's instance var"
end
end
Foo.new { |foo| puts foo.var }
The problem is that the block passed to the new constructor is never
called! Why?
Which is the best way to redefine a constructor when a class is re-opened?
Thanks!
Andrea
I'd like to re-open a class and to re-initialize its original constructor:
class Foo
def initialize
yield self if block_given?
end
end
class Foo
attr_reader :var
alias foo_initialize initialize
def initialize
foo_initialize
@var = "Foo's instance var"
end
end
Foo.new { |foo| puts foo.var }
The problem is that the block passed to the new constructor is never
called! Why?
Which is the best way to redefine a constructor when a class is re-opened?
Thanks!
Andrea