`alias`랑 `alias_method` 둘 중 어느걸 쓰는게 맞나요?
조회수 1684회
같은 클래스 내에서 메소드를 alias할건데 어느 쪽을 쓰는게 맞나요?
이름만 보면 alias_method
를 쓰는게 맞는 것 같은데 alias
를 써도 크게 문제 없는 걸 보면 왜 굳이 2개를 나눠놨나..하는 생각도 듭니다
1 답변
-
먼저 말하자면,
alias
는 키워드 입니다.alias_method
는 메소드로, 재정의될 수 있습니다.
Gives alias to methods or global variables. Aliases can not be defined within the method body. The aliase of the method keep the current definition of the method, even when methods are overridden. Making aliases for the numbered global variables ($1, $2,...) is prohibited. Overriding the builtin global variables may cause serious problems.
method나 전역변수의 alias를 만듭니다. method body안에서는 정의할 수 없습니다. method가 overrid되더라도 해당 메소드의 alias는 유지됩니다. numbered 전역변수($1, $2, ...)의 alias는 금지되어있습니다. 내장된 전역변수를 alias하는건 심각한 문제를 야기할 수도 있습니다
alias_method(new_name, old_name) → self
Makes
new_name
a new copy of the methodold_name
. This can be used to retain access to methods that are overridden.old_name
메소드를 복사한new_name
메소드를 만듭니다. overrid된 메소드도 접근할 수 있습니다.
댓글 입력