Ruby Access visiblity keyword(private, protected, public) are not actually keywords these're Functions .. and Does super keyword do?
2007/12/31 15:10
일단 처음 public 키워드가 키워드가 아닐지도 모른다는 의심이 든건 다음 코드를 본 직후였다.
private(:methodP)
어라 웬 Function?
구글링을 통한 조사 결과
위키북에서 그 실마리를 찾아 볼 수 있었다.
그 아래 레퍼런스를 적어두었는데 링크는 깨져있었다.
혹시나 해서 레퍼런스를 찾아보니
Module#public 이라는 메소드가 나왔다
아.. 루비에서 접근제한자는 키워드가 아니라 메소드였구나...
새로운 시각의 접근이라는 생각이 들었는데
또다시 떠오른 의문점은..
패턴이 똑같은
super 키워드 였다.
슈퍼 키워드의 사용법은 다음과 같다.
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
으흠
과연 어떻게 해야 알 수 있을런지..
마지막의 private 키워드가 마치 다음과 같이 보였다class Example
def methodA
end
def methodP
end
private :methodP
end
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
으흠
과연 어떻게 해야 알 수 있을런지..
'direct' 카테고리의 다른 글
| PermGen Space와 eclipse.ini 파일 수정 (0) | 2008/01/10 |
|---|---|
| Ruby Access visiblity keyword(private, protected, public) are not actually keywords these're Functions .. and Does super keyword do? (0) | 2007/12/31 |
| Enum class 과 Generic method 그리고 Prefer Wildcard (0) | 2007/12/31 |
| LG my070 의 Wifi 폰 WPU-7000을 해킹해보고 싶다.. (0) | 2007/12/24 |

