T
Tim Olsen
Hello,
It appears that including module A inside another module B can cause
problems for classes that have already included A. What seems to
happen is that a class can only see the methods from module B if that
class include module A before module A includes module B.
For example,
module A
def a
puts "a"
end
end
module B
def b
puts "b"
end
end
class C
include B
def c
puts "c"
end
end
module B
include A
def b2
puts "b2"
end
end
C.new.c
C.new.b
C.new.b2
C.new.a
produces
tolsen@neurofunk:~/svn/limeade$ /var/tmp/tst.rb
c
b
b2
/var/tmp/tst.rb:42: undefined method `a' for #<C:0x2ac204fe7180> (NoMethodError)
Notice I can define b2() after C has already included B but including
A into B does nothing for C.
Any idea what's going on here?
Thanks,
Tim
It appears that including module A inside another module B can cause
problems for classes that have already included A. What seems to
happen is that a class can only see the methods from module B if that
class include module A before module A includes module B.
For example,
module A
def a
puts "a"
end
end
module B
def b
puts "b"
end
end
class C
include B
def c
puts "c"
end
end
module B
include A
def b2
puts "b2"
end
end
C.new.c
C.new.b
C.new.b2
C.new.a
produces
tolsen@neurofunk:~/svn/limeade$ /var/tmp/tst.rb
c
b
b2
/var/tmp/tst.rb:42: undefined method `a' for #<C:0x2ac204fe7180> (NoMethodError)
Notice I can define b2() after C has already included B but including
A into B does nothing for C.
Any idea what's going on here?
Thanks,
Tim