Consider this very simple logging class:
class MockLog
# ...
end
Let's add logging to all our classes:
class Module
def has_logging()
class_eval {
@log = MockLog.new
def log
self.class.instance_variable_get :@log
end
}
end
end
Now, why doesn't this work?
class Foo
has_logging
end
Foo.new.log.nil? # => false, as expected
class Bar < Foo
end
Bar.new.log.nil? # => true?! Why wasn't the `log` method inherited?