Imitating Multiple Inheritance


#1

Here is the URL:
https://www.codecademy.com/courses/ruby-beginner-en-zfe3o/2/2?curriculum_id=5059f8619189a5000201fbcb

Here is my code:

module MartialArts
    def swordsman
        puts "I'm a swordsman."
    end

class Ninja
      include MartialArts
      attr_reader :name
      def initialize(name)
        @name = name
      end
      
      def initialize(clan)
        @clan = clan
      end   
end

class Samurai
      include MartialArts
      attr_reader :name
      def initialize(name)
        @name = name
      end
  
      def initialize(shogun)
        @shogun = shogun
      end
end

Here is the Error:

(ruby):28: syntax error, unexpected $end, expecting keyword_end

Oops, try again. Did you create a module called MartialArts?

Unless I am blind I really DON'T see what I am doing wrong here?


#2

May be removed from both classes.

Your running code should accept these instantiations.

aki = Ninja.new('Aki')
kai = Samurai.new('Kai')

aki.swordsman()    # I'm a swordsman.

kai.swordsman()    # I'm a swordsman.

forego gender


#3

It worked!! I tired to do more than what they expect me to do by adding those lines:

attr_reader :name
def initialize(name)
@name = name
end

to each class

Plus module MartialArts did not have an end!

Thank you. :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.