, 당신은 다음과 같은 class << self
같은 관용구를 사용할 수 있습니다루비 : 그래서 루비 클래스에서 열기 모듈의 싱글
class SalesOrganization
def self.find_new_leads
...
end
class << self
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :find_new_leads, :category => :task
end
end
내 질문 SalesOrganization
경우 실제로 Module
대신 Class
의 인 것입니다. 이 일이 내가 원하는 일을하고있는 것입니까, 아니면 내가 손을 대지 말았어야하는 흑 마술을 열어 놓았습니까?
# Potentially terrible code
module SalesOrganization
def self.find_new_leads
...
end
class << self
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :find_new_leads, :category => :task
end
end
모듈 싱글 톤 클래스에 어떻게 액세스합니까?
이것은 실제로 모듈의 싱글 톤 클래스를 여는 방법에 대한 원래 질문에 대답하지 않습니다. 나는 그 모듈을 어디서나 포함 된 메소드에 포함시키지 않을 것이다. 나는 지금 그것을 네임 스페이스로 사용하고있다. – randombits