문제

다음을 수행하고 싶습니다.아이디어는 내가 경로에 메소드를 추가 할 수 있고 존재하는 경우 나중에 사용할 수 있습니다.Ruby 1.8을 사용하고 있습니다.

module Routes
  def home
    #stuff
  end

  def work
    #end
  end
end

Routes.method_defined? :home
# true

Routes.send(:home)
#NoMethodError: undefined method `home' for Routes:Module
.

도움이 되었습니까?

해결책

다음 코드를 사용하면 다음을 수행 할 수 있습니다.

Class.new.extend(Routes).send(:home)
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top