You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Module is a collection of methods and constants. The methods in a module may be instance methods or module methods. Instance methods appear as methods in a class when the module is included, module methods do not. Conversely, module methods may be called without creating an encapsulating object, while instance methods may not.
In the descriptions that follow, the parameter sym refers to a symbol, which is either a quoted string or a Symbol (such as :name).
Allows us to create new classes whose behavior is based on, but modified from, the behavior of an existing class.
If we define a class Ruby that extends a class Gem, we say that Ruby is a subclass of Gem, and that Gem is the superclass of Ruby.
If you do not specify a superclass when you define a class, then your class implicitly extends Object.
extend: extend(module, ...) → obj
Just mix the instance methods from each of the given modules in to obj.
include: include(module, ...) → self
Invokes Module.append_features on each parameter in reverse order.
The module that you include is effectively added as a superclass of the class
being defined.
It’s as if the module is the parent of the class that it is
mixed into.
prepend: prepend(module, ...) → self
Invokes Module.prepend_features on each parameter in reverse order.
Ruby 2 introduced the prepend method.
Logically, this behaves just like include, but the methods in the prepended module take precedence over those in the host class. Ruby pulls off this magic by inserting a dummy class in
place of the original host class and then inserting the prepended module between the two.
Bootstraps the class hierarchy
Document-class: BasicObject
Document-class: Object
Document-class: Kernel
Document-class: Module
Init class hierarchy
The text was updated successfully, but these errors were encountered: