More actions
No edit summary |
(Repair MoniWiki formatting after migration) |
||
| Line 36: | Line 36: | ||
2 는 다음과 같다. | 2 는 다음과 같다. | ||
Library::Service | Library::Service | ||
Revision as of 14:01, 26 March 2026
[[pagelist(^RubyLanguage)]]
클래스
변수와 상수
모듈
- 인스턴스화 할 수 없는 클래스
- Class 클래스는 Module 클래스의 서브 클래스
- 클래스 = 모듈 + 인스턴스화 능력
- 기능
- Mix-in
- Namespace
Mix-in
- 제한된 다중상속
- Ruby는 단일상속만을 지원한다.
- 따라서 클래스는 하나만 상속할 수 있다.
- 그러나 모듈은 여러개를 상속받을 수 있다.
- Include : 클래스가 모듈을 상속받는 것.
Namespace
// 1 class Service end // 2 module Library class Service end end
- 앞의 Service 클래스는 최상위 레벨의 namespace에 속해 있고, 뒤의 Service 클래스는 Library 모듈에 속해 있다.
위의 두 가지는 다음의 차이가 있다 1은 다음과 같이 사용할 수 있다.
Service
또는
::Service
2 는 다음과 같다.
Library::Service