Forum: Ruby on Rails Got error on method overriding :(

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
744cfce78b48b778228b301e38eac52e?d=identicon&s=25 Volodymyr Gl (Guest)
on 2009-04-28 19:03
(Received via mailing list)
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 method `printme' for nil:NilClass
(NoMethodError)
init
FooPrint
        from C:/Users/Volodymyr/Documents/NetBeansProjects/
RubyApplication3/lib/main.rb:22
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-28 21:36
(Received via mailing list)
On Apr 28, 6:02 pm, Volodymyr Gl <int...@gmail.com> wrote:

> class Foo2 < Foo
>   def printme
>     super.printme
>   end
> end
>
in ruby super calls the ancestor method. No need to append .printme

Fred
744cfce78b48b778228b301e38eac52e?d=identicon&s=25 Volodymyr Gl (Guest)
on 2009-04-28 22:17
(Received via mailing list)
Fred, thank you very much!

On Apr 28, 10:35 pm, Frederick Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.