로딩
요청 처리 중입니다...

Rails Autoloading: Classic과 Zeitwerk의 차이점 이해하기

 Rails Autoloading: Classic과 Zeitwerk의 차이점 이해하기

들어가며 Ruby on Rails의 오토로딩(Autoloading)은 개발자가 파일을 수동으로 require 하지 않아도 클래스와 모듈을 필요할 때 자동으로 불러오는 편리한 기능이다. 이 오토로딩 방식은 Rails 6를 기점으로 크게 변경되었다.

과거의 'classic' 방식에서 'zeitwerk' 방식으로 전환되면서 파일 탐색 및 로딩 메커니즘에 중요한 차이가 생겼다. 디렉터리 구조 오토로딩 방식의 차이를 이해하기 위해 다음과 같은 파일 구조를 가정해 보자. .

app/ controllers/ api/ users/ v1/ users_controller.rb services/ users/ show_user_service.rb show_user_service.rb module Users class ShowUserService def self.call(...) ShowUserService.new.call(...) end def call "Hello, world!"...