Watson1978
4/21/2011 - 2:26 PM

for http://d.hatena.ne.jp/rahaema/20110415#p1

class Foo
  def initialize
    @obj = true
    if block_given?
      yield
    end
  end
end

class Bar < Foo
  def initialize
    @obj = false
    if block_given?
      yield self
    end
    super
  end
end

f = nil
obj = Bar.new { |x|
  f ||= x
  if x.nil? && !f.nil?
    f.instance_variable_set(:@obj, false)
  end
}
p obj