Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

RubyLanguage/Class: Difference between revisions

From ZeroWiki
No edit summary
(Repair batch-0003 pages from live compare)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[pagelist(^RubyLanguage)]]
<!-- MONIWIKI PageList(^RubyLanguage) -->
* [[RubyLanguage]]
* [[RubyLanguage/Class]]
* [[RubyLanguage/Container]]
* [[RubyLanguage/DataType]]
* [[RubyLanguage/ExceptionHandling]]
* [[RubyLanguage/Expression]]
* [[RubyLanguage/InputOutput]]
__TOC__
__TOC__


Line 18: Line 25:
* '''Include''' : 클래스가 모듈을 상속받는 것.
* '''Include''' : 클래스가 모듈을 상속받는 것.
== Namespace ==
== Namespace ==
  class Service; end
// 1
  class Service
end
// 2
  module Library
  module Library
   class Service; end
   class Service
  end
  end
  end
* 앞의 Service 클래스는 최상위 레벨의 namespace에 속해 있고, 뒤의 Service 클래스는 Library 모듈에 속해 있다.
* 앞의 Service 클래스는 최상위 레벨의 namespace에 속해 있고, 뒤의 Service 클래스는 Library 모듈에 속해 있다.  
위의 두 가지는 다음의 차이가 있다
1은 다음과 같이 사용할 수 있다.
Service
또는
::Service


2 는 다음과 같다.
Library::Service

Latest revision as of 00:29, 27 March 2026

클래스

변수와 상수

모듈

  • 인스턴스화 할 수 없는 클래스
  • 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