Inheriting module/class methods

Richlewis

I have this module with a method:

module MySqlConnection
  def database_connect(application)
    # Code in here
  end
end

I have a second module with a class that uses database_connect:

module ResetPopups
  class PopupsOff
    include MySqlConnection
    def self.reset_popup
      database_connect("#{APP}")
    end
  end
end

When I call:

ResetPopups::PopupsOff.reset_popup

I get an undefined method database_connect. Why does this happen?

Andrey Deineko
module ResetPopups
  class PopupsOff
    extend MySqlConnection
    def self.reset_popup
      database_connect("#{APP}")
    end
  end
end

would work

What is hapening here, is that you include MySqlConnection, which makes method defined in it (database_connect) instance methods. But you use this module in the class scope, calling the database_connect on the class.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Perl not inheriting base methods

From Dev

C# "Inheriting" Static Methods?

From Dev

Inheriting old methods in version 8

From Dev

Inheriting math methods into a class with only static methods

From Dev

Regarding Java subclasses inheriting methods that return "this"

From Dev

Regarding Java subclasses inheriting methods that return "this"

From Dev

Javascript inheriting properties and methods from a class?

From Dev

Python: Inheriting methods of a parent class without being a child of the class

From Dev

TypeScript: self-referencing return type for static methods in inheriting classes

From Dev

TypeScript: self-referencing return type for methods in inheriting classes

From Dev

C++ Inheriting Function Pointer that can be used with derived only methods

From Dev

Problems with subclasses inheriting class factory methods (Objective-C)

From Dev

TypeScript: self-referencing return type for methods in inheriting classes

From Dev

OO PHP - child class not inheriting parent methods and properties

From Dev

ES6 OOP inheriting methods from parent class

From Dev

Ruby subclass not inheriting parent method or not able to call parent methods in class body

From Dev

Ruby subclass not inheriting parent method or not able to call parent methods in class body

From Dev

C# Asp.Net MVC Inheriting Abstract Class Methods On An Interface

From Dev

Inheriting typedefs?

From Dev

Inheriting NSDecimalNumber

From Dev

Inheriting PShape

From Dev

Inheriting a subtype

From Dev

Inheriting RLMObject

From Dev

Inheriting NSDecimalNumber

From Dev

Inheriting PShape

From Dev

Inheriting member function pointers

From Dev

Is inheriting constructors part of the standard?

From Dev

Inheriting F# Record

From Dev

Is inheriting from the EventEmitter an antipattern?

Related Related

  1. 1

    Perl not inheriting base methods

  2. 2

    C# "Inheriting" Static Methods?

  3. 3

    Inheriting old methods in version 8

  4. 4

    Inheriting math methods into a class with only static methods

  5. 5

    Regarding Java subclasses inheriting methods that return "this"

  6. 6

    Regarding Java subclasses inheriting methods that return "this"

  7. 7

    Javascript inheriting properties and methods from a class?

  8. 8

    Python: Inheriting methods of a parent class without being a child of the class

  9. 9

    TypeScript: self-referencing return type for static methods in inheriting classes

  10. 10

    TypeScript: self-referencing return type for methods in inheriting classes

  11. 11

    C++ Inheriting Function Pointer that can be used with derived only methods

  12. 12

    Problems with subclasses inheriting class factory methods (Objective-C)

  13. 13

    TypeScript: self-referencing return type for methods in inheriting classes

  14. 14

    OO PHP - child class not inheriting parent methods and properties

  15. 15

    ES6 OOP inheriting methods from parent class

  16. 16

    Ruby subclass not inheriting parent method or not able to call parent methods in class body

  17. 17

    Ruby subclass not inheriting parent method or not able to call parent methods in class body

  18. 18

    C# Asp.Net MVC Inheriting Abstract Class Methods On An Interface

  19. 19

    Inheriting typedefs?

  20. 20

    Inheriting NSDecimalNumber

  21. 21

    Inheriting PShape

  22. 22

    Inheriting a subtype

  23. 23

    Inheriting RLMObject

  24. 24

    Inheriting NSDecimalNumber

  25. 25

    Inheriting PShape

  26. 26

    Inheriting member function pointers

  27. 27

    Is inheriting constructors part of the standard?

  28. 28

    Inheriting F# Record

  29. 29

    Is inheriting from the EventEmitter an antipattern?

HotTag

Archive