Comments (1)
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 classGem
, we say thatRuby
is a subclass ofGem
, and thatGem
is the superclass ofRuby
. - 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.
- Invokes
- 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.
- Invokes
from dylanninin.com.
Related Issues (20)
- 《Linux Shell Scripting Essentials》
- Webhook security
- dhcp
- Security HOT 6
- scrapy
- 《Crypto 101》
- 《Introduction to Machine Learning with Python》
- NoPoint HOT 6
- 《你凭什么做好互联网》
- Email HOT 7
- 《OpenSSL Cookbook》
- 《OpenVPN Cookbook》
- 《聊聊架构》
- Resignation HOT 6
- docsify
- r/Place HOT 1
- Ansible HOT 6
- Architecture
- WeChat API Libraries
- GitHub Issue as a Blog HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dylanninin.com.