Got error on method overriding :(


#1

What is wrong with this code? Running on ruby 1.8.6
#==================================
module MFoo
def printme
puts ‘MFooPrint’
end
def initialize
puts ‘init’
end
end
class Foo
include MFoo
def printme
puts ‘FooPrint’
end
end
class Foo2 < Foo
def printme
super.printme
end
end

s = Foo2.new;
s.printme
#==================================

This code outputs:

C:/Users/Volodymyr/Documents/NetBeansProjects/RubyApplication3/lib/
main.rb:17:in printme': undefined methodprintme’ for nil:NilClass
(NoMethodError)
init
FooPrint
from C:/Users/Volodymyr/Documents/NetBeansProjects/
RubyApplication3/lib/main.rb:22


#2

On Apr 28, 6:02 pm, Volodymyr Gl removed_email_address@domain.invalid wrote:

class Foo2 < Foo
def printme
super.printme
end
end

in ruby super calls the ancestor method. No need to append .printme

Fred


#3

Fred, thank you very much!

On Apr 28, 10:35 pm, Frederick C. removed_email_address@domain.invalid