0
특정 모듈을 "special"로 태그 지정하고자하는 모듈이 M
입니다.이 모듈에서 혼합 된 클래스는 주어진 메소드 이름이 특별한. 나는 클래스 메소드 self.special
에서 인스턴스 메소드를 호출 할 수 없기 때문에믹싱 클래스에서 참조 용 모듈의 태그 달기
module M
def specials
@specials ||= {}
end
def self.special name
specials[name] = true
end
def is_special? name
specials[name]
end
def meth1
...
end
special :meth1
end
class C
include M
def check name
is_special? name
end
end
은 물론이 작동하지 않습니다 : 이것은 내가 무엇을 시도했다입니다. 모듈의 원하는 메소드 아래에 special :<name>
을 호출 할 수있는 기능을 유지하려면 클래스 변수 (예 : @@specials
)를 사용하는 것이 좋지만 누군가 나를 잘못 판단 할 수 있습니까?