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
On Apr 28, 6:02 pm, Volodymyr Gl <int...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> class Foo2 < Foo > def printme > super.printme > end > end >in ruby super calls the ancestor method. No need to append .printme Fred
Fred, thank you very much! On Apr 28, 10:35 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 28, 6:02 pm, Volodymyr Gl <int...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > class Foo2 < Foo > > def printme > > super.printme > > end > > end > > in ruby super calls the ancestor method. No need to append .printme > > Fred