일단 처음 public 키워드가 키워드가 아닐지도 모른다는 의심이 든건 다음 코드를 본 직후였다.
class Example
def methodA
end

def methodP
end

private :methodP
end
마지막의 private 키워드가 마치 다음과 같이 보였다

private(:methodP)

어라 웬 Function?

구글링을 통한 조사 결과

위키북에서 그 실마리를 찾아 볼 수 있었다.

It is interesting that these are not actually keywords, but actual methods that operate on the class, dynamically altering the visibility of the methods.


그 아래 레퍼런스를 적어두었는데 링크는 깨져있었다.

혹시나 해서 레퍼런스를 찾아보니

Module#public 이라는 메소드가 나왔다

------------------------------------------------------------------- Module#public
public                 => self
public(symbol, ...)    => self
---------------------------------------------------------------------------------
With no arguments, sets the default visibility for subsequently defined methods to public. With arguments, sets the named methods to have public visibility.


아.. 루비에서 접근제한자는 키워드가 아니라 메소드였구나...

새로운 시각의 접근이라는 생각이 들었는데

또다시 떠오른 의문점은..

패턴이 똑같은

super 키워드 였다.

슈퍼 키워드의 사용법은 다음과 같다.

class Test
    def to_s
       super
    end
end

super라고 써도 되고
super(parameter)라고 써도 된다.

이것도 함수로 구현된 것은 아닐까?

그럼 역시 함수로 구현되었다는 증거를 찾아보았다.

API에는 Class#superclass라는 것은 있었지만 super는 없었다.

구글링에도 아무런 소득이 없어서

테스트 코드를 작성해보았다.

def to_s
super()
end

=> 정상동작

def to_s
self.super()
end

=> undefined method

this.super() => undefined local variable

System.super() => NameError: uninitialized constant Test::System

으흠

과연 어떻게 해야 알 수 있을런지..

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 허혁

댓글을 달아주세요:: 네티켓은 기본, 스팸은 사절

◀ PREV : [1] : ... [40] : [41] : [42] : [43] : [44] : [45] : [46] : [47] : [48] : ... [88] : NEXT ▶

BLOG main image
안녕하세요. 안정된 코딩, 여유로운 프로젝트, 떠오르는 코더 by 허혁

카테고리

분류 전체보기 (88)
direct (50)
indirect (21)
transmissive (10)
agenda (4)
idea (3)

달력

«   2008/07   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

최근에 달린 레몬펜 쪽지

Statistics Graph
Creative Commons License

이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이선스에 따라 이용하실 수 있습니다.