clockworkpc
clockworkpc

Reputation: 688

Creating a Child Class from a Child Class in Rails

Name of Rails Application: "KayNein"

Files and Folders:

KayNein Module:

Module KayNein
end

Handler Class:

Module KayNein
  class KayNein
    def initialize(browser)
      @browser = browser
    end
  end
end

Demo Class:

Module KayNein
  class Demo < Handler
  end
end

So far, so good.

However, I want to create a subdirectory -- app/kay_nein/sites/demo/jira/ -- and put in small child classes of Demo that inherit all the methods up the chain.

How can I do so? I've tried different permutations, but I always get an error message along these lines:

<module:KayNein>': superclass mismatch for class Rdm (TypeError)

Upvotes: 0

Views: 74

Answers (1)

Wizard of Ogz
Wizard of Ogz

Reputation: 12643

You are specifying the superclass of KayNein::Rdm more than once. It is not apparent from the information you gave how this is happening in your application.

To resolve the issue you need to find all definitions for the Rdm class and ensure that the superclass for each one matches the others.

Here is an example of code which results in the same error you are encountering. Notice that class Rdm is specified more than once. This is allowed, but only if the superclass matches the initial superclass or if the superclass is omitted.

> class Parent; end
>
> module KayNein
>   class Rdm; end            # Initial class definition is OK
>   class Rdm < Parent; end   # Raises error because `Parent` does not match the superclass from the previous line.
>   class Rdm; end            # This would be OK because it matches the original class definition.
> end

Traceback (most recent call last):
        3: from /Users/andyogzewalla/.asdf/installs/ruby/2.5.1/bin/irb:11:in `<main>'
        2: from (irb):4
        1: from (irb):6:in `<module:KayNein>'
TypeError (superclass mismatch for class Rdm)

Upvotes: 1

Related Questions