including a module won’t override the methods in the class it is
included
into. For example, I’ll run some code on MRI to explain this:
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
module Cool
def lame
“Dude, that is so lame.”
endend
class Hipster
include Cool
def lame
“You’ve probably never heard of it. Because you’re lame.”
endend
hipster = Hipster.new
hipster.lame # => “You’ve probably never heard of it. Because you’re
lame.”
As you can see, despite including the module, it doesn’t override the
method #lame. Now what I can do is call #super, watch:
module Cool
def lame
“Dude, that is so lame.”
endend
class Hipster
include Cool
def lame
“You’ve probably never heard of it. Because you’re lame.”
super
endend
hipster = Hipster.new
hipster.lame # => “Dude, that is so lame.”
Including a module places that module into the class’s object heirarchy.
So
it’s method’s don’t override the class’s instance methods. Instead, they
become super to those methods. One way to achieve something like the
result
you are after is to extend the instance of the class with the module.
Like
so:
module Cool
def lame
“Dude, that is so lame.”
endend
class Hipster
def lame
“You’ve probably never heard of it. Because you’re lame.”
endend
hipster = Hipster.new.extend(Cool)
hipster.lame # => Dude, that is so lame.
Hope that explains what you are running into. This actually has nothing
to
do with jruby and java, it is just how ruby works.