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
No edit summary
Line 18: Line 18:
* '''Include''' : 클래스가 모듈을 상속받는 것.
* '''Include''' : 클래스가 모듈을 상속받는 것.
== Namespace ==
== Namespace ==
*
  class Service; end
  class Service; end
  module Library
  module Library
   class Service; end
   class Service; end
  end
  end
** 앞의 Service 클래스는 최상위 레벨의 namespace에 속해 있고, 뒤의 Service 클래스는 Library 모듈에 속해 있다.
* 앞의 Service 클래스는 최상위 레벨의 namespace에 속해 있고, 뒤의 Service 클래스는 Library 모듈에 속해 있다.



Revision as of 08:05, 24 January 2011

[[pagelist(^RubyLanguage)]]

클래스

변수와 상수

모듈

  • 인스턴스화 할 수 없는 클래스
  • Class 클래스는 Module 클래스의 서브 클래스
    • 클래스 = 모듈 + 인스턴스화 능력
  • 기능
    • Mix-in
    • Namespace

Mix-in

  • 제한된 다중상속
    • Ruby는 단일상속만을 지원한다.
    • 따라서 클래스는 하나만 상속할 수 있다.
    • 그러나 모듈은 여러개를 상속받을 수 있다.
  • Include : 클래스가 모듈을 상속받는 것.

Namespace

class Service; end
module Library
  class Service; end
end
  • 앞의 Service 클래스는 최상위 레벨의 namespace에 속해 있고, 뒤의 Service 클래스는 Library 모듈에 속해 있다.