1
폴더에 임의 모듈 파일이 있습니다.모듈 파일을 요구하고 해당 모듈과 상호 작용합니까?
예 : "module User"가 들어있는 "user.rb", "module Customer"가 들어있는 "customer.rb"등이 있습니다.
모든 파일을 요구하고 모든 모듈 방법을 인쇄하고 싶습니다. 여기
내 현재 코드입니다 :
@@data_module_methods = []
# iterate through all files in the data folder
Dir[File.join(APP_ROOT, "data", "*.rb")].each do |file|
require file
# give me the module name from the filepath (so ./data/user.rb will give me User)
data_module_name = file.split("/").[](-1).split(".").[](0).capitalize
# ERROR: print all method names, HERE IT FAILS BECAUSE data_module_name is a string and not the module:)
data_module_name.instance_methods.each do |method|
@@data_module_methods << method
end
end
내가 어떻게 이런 일을 할 수 있습니까?
감사