How to override a method defined in Ruby module

Greetings,

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?

Thanks in advance,
Alex

2008/4/7, Sonar V. [email protected]:

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.

Kind regards

robert

Robert K. wrote:

2008/4/7, Sonar V. [email protected]:

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.

Kind regards

robert

Ok thanks!

Is there module inheritance in Ruby?

On Mon, Apr 7, 2008 at 7:33 AM, Sonar V. [email protected]
wrote:

Is there module inheritance in Ruby?

No, and yes.

You can’t do

module A
end

module B < A
end

but you can do:

module B
include A
end

Which acts like a sort of inheritance.

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

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 :frowning: (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.

Cheers
Robert


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/


http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Greetings Alex,

Overriding the metohd in a module

save this snippet of code as sample.rb file

module Sample
def display
puts “Inside a mosdule”
end
end

*write another file test.rb *

require ‘sample’

class Test
include Sample
def display
puts “Inside the class”
end
end

Test.new.display # OUTPUT : Inside the class

See here display method in the *class Test overrides *the
displaymethod in
*Module Sample

On Mon, Apr 7, 2008 at 3:25 PM, Sonar V. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs