GithubHelp home page GithubHelp logo

Comments (1)

dylanninin avatar dylanninin commented on July 20, 2024

Classes

 //ruby/class.c
 * class Classes and their hierarchy.
 * Terminology
 * - class: same as in Ruby.
 * - singleton class: class for a particular object
 * - eigenclass: = singleton class
 * - metaclass: class of a class. metaclass is a kind of singleton class.
 * - metametaclass: class of a metaclass.
 * - meta^(n)-class: class of a meta^(n-1)-class.
 * - attached object: A singleton class knows its unique instance.
 *   The instance is called the attached object for the singleton class.

Inheritances and Mixins

  • inherit: superclass
    • 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.

from dylanninin.com.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.