I’m new in Ruby, so my question might seem a bit stupid. I have a
third-party module wired into my project (ActiveScaffold). It defines
some empty method:
module ActiveScaffold::Actions
module Update
......
# override this method if you want to do something after the save
def after_update_save(record); end
end
end
which I need to override. How do I do this?
You simply define it in the class that includes this module. Or you
define it in a module that inherits this module.
which I need to override. How do I do this?
You simply define it in the class that includes this module. Or you
define it in a module that inherits this module.
On Mon, Apr 7, 2008 at 1:45 PM, Rick DeNatale [email protected]
wrote:
module B < A
end
but you can do:
module B
include A
end
Which acts like a sort of inheritance.
It does indeed look like that if you ask ruby itself, very much to my
dispair (but that’s why I have implemented traits)
irb(main):001:0> a=Module::new
=> #Module:0xb7cf35e8
irb(main):002:0> b=Module::new
=> #Module:0xb7cebf78
irb(main):003:0> b.send :include, a
=> #Module:0xb7cebf78
irb(main):005:0> b < a
=> true
irb(main):006:0> c=Class::new
=> #Class:0xb7cd8edc
irb(main):007:0> c.send :include, b
=> #Class:0xb7cd8edc
irb(main):008:0> c.new.is_a? a
=> true
I believe that this is misleading I might agree to
c.new.behaves_like? a
but if we go all the way to ducktyping even that is unacceptable.
And yes you guessed correctly I am an inheritance skeptic but that is
not because it is a bad feature (single inheritance) but it is not the
right feature for code reuse, it is the right feature for modeling.
Smalltalk which had no mixins suffered a lot from having to use SI for
refactoring and code reuse, Squeak implemented traits for that very
reason if I understood correctly.